swagger-api / swagger-parser

Swagger Spec to Java POJOs
http://swagger.io
Apache License 2.0
785 stars 531 forks source link

Schema type is null #1864

Closed ihsanciftci closed 1 year ago

ihsanciftci commented 1 year ago

I'm parsing sendgrid api: https://raw.githubusercontent.com/sendgrid/sendgrid-oai/main/oai_v3_stoplight.json The types of some schemas are null but they are not in the json.

PS. Java Version: 18 swagger-parser version: 2.1.9

(I'm using stoplight version because original version (https://raw.githubusercontent.com/sendgrid/sendgrid-oai/main/oas_v3.json) contains references to other files. And swagger java parser cannot handle reference name containing curly braces. That's another story or bug)

        String url = "https://raw.githubusercontent.com/sendgrid/sendgrid-oai/main/oai_v3_stoplight.json";

        ParseOptions options = new ParseOptions();
        options = null;
        //options.setResolve(true);
        //options.setFlatten(true);

        SwaggerParseResult result = new OpenAPIParser().readLocation(url, null, options);
        OpenAPI openAPI = result.getOpenAPI();

e.g. for schema type is null

{
    "mail_send": {
        "post": {
            "operationId": "POST_mail-send",
            "summary": "v3 Mail Send",
            "tags": [
                "Mail Send"
            ],
            "requestBody": {
                "content": {
                    "application/json": {
                        "schema": {
                            "type": "object",
                            "properties": {
                                "personalizations": {
                                    "type": "array",
                                    "description": "An array of messages and their metadata. Each object within personalizations can be thought of as an envelope - it defines who should receive an individual message and how that message should be handled. See our [Personalizations documentation](https://sendgrid.com/docs/for-developers/sending-email/personalizations/) for examples.",
                                    "uniqueItems": false,
                                    "maxItems": 1000,
                                    "items": {}
                              }
                        }
                  }
            }
     }
ihsanciftci commented 1 year ago

After debugging the API, I have realized that instead of setting type attribute, API adds it to types attribute. Is it related with v3.1?

frantuma commented 1 year ago

yes, please see Swagger Core Wiki

and this comment for a discouraged option to have type bound to types

For 3.1 specs please use Yaml31 and Json31 helper classes for serialization

please close ticket if this answers your question