-
Notifications
You must be signed in to change notification settings - Fork 537
Closed
Milestone
Description
In an example I defined the schema for a data structure with a single property which has an enumeration type. I use the allOf keyword (as a wrapper construct) in order to be allowed to also specify a description for the property:
components:
schemas:
TestDTO:
required:
- choice
type: object
properties:
choice:
description: Choice description
allOf:
- $ref: '#/components/schemas/TestEnum'
TestEnum:
type: string
enum:
- One
- Two
- ThreeI then use the Swagger Parser v3 to parse (and print afterwards) the above definition (embedded in a complete OpenAPI document).
String apiDefinition;
try (Reader apiDefinitionReader = new InputStreamReader(new ClassPathResource("test.yaml").getInputStream())) {
apiDefinition = CharStreams.toString(apiDefinitionReader);
}
OpenAPIV3Parser parser = new OpenAPIV3Parser();
ParseOptions options = new ParseOptions();
options.setResolve(true);
options.setResolveCombinators(true);
options.setResolveFully(true);
options.setFlatten(true);
OpenAPI openAPI = parser.readContents(apiDefinition, /* auths: */ null, options).getOpenAPI();
System.out.println(Yaml.mapper().writeValueAsString(openAPI));The output is then as follows:
openapi: 3.0.1
info:
title: Test
description: Description
version: "1"
servers:
- url: /
tags:
- name: Test
description: Test tag description
paths:
/do-something:
post:
tags:
- Test
description: Do something operation description
operationId: do-something
requestBody:
content:
application/json:
schema:
required:
- choice
type: object
properties:
choice: {}
responses:
"200":
description: Do something operation result description
components:
schemas:
TestDTO:
required:
- choice
type: object
properties:
choice: {}
TestEnum:
type: string
enum:
- One
- Two
- ThreeIt seems the the parser cannot process the allOf construct correctly.
Metadata
Metadata
Assignees
Labels
No labels