swagger-api / swagger-inflector

Apache License 2.0
158 stars 85 forks source link

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

Open RonakPrajapatiPanamax opened 2 months ago

RonakPrajapatiPanamax commented 2 months ago

Problem

Observation

Steps to Reproduce

Expected Behavior

Actual Behavior

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.

fehguy commented 2 months ago

Please share where you're getting the 3.1 pet store document?

RonakPrajapatiPanamax commented 2 months ago

@fehguy Thanks for reply, You can find open API 3.1 Spec file. URL : https://editor-next.swagger.io/ File --> Load Example --> OpenAPI 3.1 Petstore

I am also attaching same file here. petStore3.1.0.json