Skip to content

Do not remove schemas with only a default value form allOf schemas #21189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2375,7 +2375,8 @@ public static boolean isMetadataOnlySchema(Schema schema) {
schema.getContains() != null ||
schema.get$dynamicAnchor() != null ||
schema.get$anchor() != null ||
schema.getContentSchema() != null;
schema.getContentSchema() != null ||
schema.getDefault() != null;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1205,4 +1205,18 @@ public void doNotWrapSingleAllOfRefs() {
assertNotNull(allOfRefWithDescriptionAndReadonly.getAllOf());
assertEquals(numberRangeRef, ((Schema) allOfRefWithDescriptionAndReadonly.getAllOf().get(0)).get$ref());
}

@Test
public void testAllOfEnumWithDefault() {
// The flattened spec should still have both allOf items in query parameter, to allow generators to generate the default value
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/allOf-enum-default.yaml");
var parameters = openAPI
.getPaths()
.get("/person")
.getGet()
.getParameters();
assertEquals(1, parameters.size());
var parameter = parameters.get(0);
assertEquals(2, parameter.getSchema().getAllOf().size());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
openapi: 3.0.1
info:
version: 1.0.0
title: Example
license:
name: MIT
servers:
- url: http://api.example.xyz/v1
paths:
/person:
get:
parameters:
- name: enum
in: query
required: true
description: Enum value
schema:
allOf:
- $ref: '#/components/schemas/MyEnum'
- default: "One"
operationId: list
responses:
'200':
description: OK
components:
schemas:
MyEnum:
type: string
enum:
- One
- Two
Loading