Skip to content

Failure of ExampleBuilder Class to Parse JSON Schema, Resulting in Blank JSON Example when using Swagger Parser and Swagger Inflector #471

Open
@RonakPrajapatiPanamax

Description

@RonakPrajapatiPanamax

Problem

  • I am encountering an issue when trying to parse OpenAPI JSON 3.1.0 examples of the Petstore. It seems that the ExampleBuilder class from io.swagger.oas.inflector.examples.ExampleBuilder does not support parsing JSON Schema, which is generated by the Swagger parser for 3.1.0 OpenAPI specs.

Observation

  • Upon reviewing the code of the ExampleBuilder class, it appears that there is no support for parsing JSON Schema.

Steps to Reproduce

  • Obtain the Petstore OpenAPI JSON 3.1.0 example.
  • Attempt to parse it using the Swagger parser and utilize the ExampleBuilder class to generate a JSON Example from the schema object.

Expected Behavior

  • The ExampleBuilder class should be able to parse the JSON Schema generated by the Swagger parser for 3.1.0 OpenAPI specs.

Actual Behavior

  • The ExampleBuilder class fails to parse the JSON Schema, resulting in a blank JSON example without keys and values.

Code Snippet.

		ParseOptions parseOptions = new ParseOptions();
		parseOptions.setResolve(true);
		parseOptions.setResolveFully(true);
		SwaggerParseResult parseResult = new OpenAPIV3Parser().readLocation(specUrl, null, parseOptions);

		if (parseResult.getMessages() != null && !parseResult.getMessages().isEmpty()) {
			for (String message : parseResult.getMessages()) {
				System.out.println("Parsing message: " + message);
			}
		}
		OpenAPI openAPI = parseResult.getOpenAPI();
		Map<String, Schema> definitions = openAPI.getComponents().getSchemas();
		Schema model = definitions.get("Pet");
		Example example = ExampleBuilder.fromSchema(model, model.getProperties());

		SimpleModule simpleModule = new SimpleModule().addSerializer(new JsonNodeExampleSerializer());
		Json.mapper().registerModule(simpleModule);
		String jsonExample = Json.pretty(example);
		System.out.println(jsonExample);

Dependencies (from pom.xml)

<dependencies>
    <dependency>
        <groupId>io.swagger.parser.v3</groupId>
        <artifactId>swagger-parser</artifactId>
        <version>2.1.22</version>
    </dependency>
    <dependency>
        <groupId>io.swagger</groupId>
        <artifactId>swagger-inflector</artifactId>
        <version>2.0.12</version>
    </dependency>
</dependencies>

@fehguy and @gracekarina I have taken latest swagger-inflector version. If anyone knows any solution then please let me know.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions