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:
parent
2c826bdbba
commit
2c55e929ae
@ -56,10 +56,9 @@ const metaRules: Rule[] = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'should have properties with descriptions',
|
name: 'should have properties with descriptions',
|
||||||
match: (_, schema) => {
|
match: (_, schema) =>
|
||||||
// only match schemas that have a properties field
|
// only match schemas that have a properties field
|
||||||
return 'properties' in schema;
|
'properties' in schema,
|
||||||
},
|
|
||||||
metaSchema: {
|
metaSchema: {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
// properties of the meta schema
|
// properties of the meta schema
|
||||||
@ -91,6 +90,17 @@ const metaRules: Rule[] = [
|
|||||||
},
|
},
|
||||||
knownExceptions: [],
|
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',
|
name: 'should have a description',
|
||||||
metaSchema: {
|
metaSchema: {
|
||||||
|
@ -1,27 +1,28 @@
|
|||||||
import { FromSchema } from 'json-schema-to-ts';
|
import { FromSchema } from 'json-schema-to-ts';
|
||||||
|
|
||||||
|
const commonProps = {
|
||||||
|
environment: {
|
||||||
|
type: 'string',
|
||||||
|
example: 'development',
|
||||||
|
description: 'The environment to export from',
|
||||||
|
},
|
||||||
|
downloadFile: {
|
||||||
|
type: 'boolean',
|
||||||
|
example: true,
|
||||||
|
description: 'Whether to return a downloadable file',
|
||||||
|
},
|
||||||
|
} as const;
|
||||||
|
|
||||||
export const exportQuerySchema = {
|
export const exportQuerySchema = {
|
||||||
$id: '#/components/schemas/exportQuerySchema',
|
$id: '#/components/schemas/exportQuerySchema',
|
||||||
type: 'object',
|
type: 'object',
|
||||||
required: ['environment'],
|
|
||||||
description:
|
description:
|
||||||
'Available query parameters for the [deprecated export/import](https://docs.getunleash.io/reference/deploy/import-export) functionality.',
|
'Available query parameters for the [deprecated export/import](https://docs.getunleash.io/reference/deploy/import-export) functionality.',
|
||||||
properties: {
|
|
||||||
environment: {
|
|
||||||
type: 'string',
|
|
||||||
example: 'development',
|
|
||||||
description: 'The environment to export from',
|
|
||||||
},
|
|
||||||
downloadFile: {
|
|
||||||
type: 'boolean',
|
|
||||||
example: true,
|
|
||||||
description: 'Whether to return a downloadable file',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
oneOf: [
|
oneOf: [
|
||||||
{
|
{
|
||||||
required: ['features'],
|
required: ['environment', 'features'],
|
||||||
properties: {
|
properties: {
|
||||||
|
...commonProps,
|
||||||
features: {
|
features: {
|
||||||
type: 'array',
|
type: 'array',
|
||||||
example: ['MyAwesomeFeature'],
|
example: ['MyAwesomeFeature'],
|
||||||
@ -34,8 +35,9 @@ export const exportQuerySchema = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
required: ['tag'],
|
required: ['environment', 'tag'],
|
||||||
properties: {
|
properties: {
|
||||||
|
...commonProps,
|
||||||
tag: {
|
tag: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
example: 'release',
|
example: 'release',
|
||||||
|
Loading…
Reference in New Issue
Block a user