1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

chore: merge one of with properties (#4763)

## About the changes
Open API code generator does not get along with `oneOf` alongside
`properties`:
```shell
$ openapi-generator-cli validate -i modified-openapi.json --recommend
Validating spec (modified-openapi.json)
Warnings: 
        - Schemas defining properties and oneOf are not clearly defined in the OpenAPI
          Specification. While our tooling supports this, it may cause issues with other tools.
```


bab67e44e4/modules/openapi-generator/src/main/java/org/openapitools/codegen/validations/oas/OpenApiSchemaValidations.java (L25-L29)

This PR adds a meta-schema rule to validate this and fixes one issue
This commit is contained in:
Gastón Fournier 2023-09-18 15:43:01 +02:00 committed by GitHub
parent 2c826bdbba
commit 2c55e929ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 18 deletions

View File

@ -56,10 +56,9 @@ const metaRules: Rule[] = [
},
{
name: 'should have properties with descriptions',
match: (_, schema) => {
match: (_, schema) =>
// only match schemas that have a properties field
return 'properties' in schema;
},
'properties' in schema,
metaSchema: {
type: 'object',
// properties of the meta schema
@ -91,6 +90,17 @@ const metaRules: Rule[] = [
},
knownExceptions: [],
},
{
name: 'should either have oneOf or properties, instead extract them in commonProps',
match: (_, schema) =>
// only match schemas that have a properties field
'properties' in schema && 'oneOf' in schema,
metaSchema: {
type: 'object',
additionalProperties: false, // this is a shortcut to say: it should fail
},
knownExceptions: [],
},
{
name: 'should have a description',
metaSchema: {

View File

@ -1,12 +1,6 @@
import { FromSchema } from 'json-schema-to-ts';
export const exportQuerySchema = {
$id: '#/components/schemas/exportQuerySchema',
type: 'object',
required: ['environment'],
description:
'Available query parameters for the [deprecated export/import](https://docs.getunleash.io/reference/deploy/import-export) functionality.',
properties: {
const commonProps = {
environment: {
type: 'string',
example: 'development',
@ -17,11 +11,18 @@ export const exportQuerySchema = {
example: true,
description: 'Whether to return a downloadable file',
},
},
} as const;
export const exportQuerySchema = {
$id: '#/components/schemas/exportQuerySchema',
type: 'object',
description:
'Available query parameters for the [deprecated export/import](https://docs.getunleash.io/reference/deploy/import-export) functionality.',
oneOf: [
{
required: ['features'],
required: ['environment', 'features'],
properties: {
...commonProps,
features: {
type: 'array',
example: ['MyAwesomeFeature'],
@ -34,8 +35,9 @@ export const exportQuerySchema = {
},
},
{
required: ['tag'],
required: ['environment', 'tag'],
properties: {
...commonProps,
tag: {
type: 'string',
example: 'release',