Skip to content
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

ItemsSchema elaboration #230

Open
dc950 opened this issue Nov 19, 2018 · 0 comments
Open

ItemsSchema elaboration #230

dc950 opened this issue Nov 19, 2018 · 0 comments

Comments

@dc950
Copy link

dc950 commented Nov 19, 2018

I am having issues with finding out if an itemsSchema exists (e.g. for an implicit array type where only the "items:" exists, which as far as I can tell is valid and no validation issues are raised from it).

When an items schema is retrieved from a schema, it will always return a schema, even if the elaborate parameter is set to true.

I'm unclear on if this is intended or a bug, but this makes it hard to distinguish between actual implicit arrays and other types. It can be especially confusing with "not" which seems to do the same thing.

E.g: The following API is valid

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Swagger Petstore
  license:
    name: MIT
paths:
  /path:
    get:
      responses:
        '200':
          description: abc
          content:
            application/json:
              schema:
                items:
                  items:
                    not:
                      items:
                        type: string

And the following code is able to recurse through itemsSchema regardless of what "elaborate" is set to:

package com.avaloq.openapi3.testing;

import com.reprezen.kaizen.oasparser.OpenApi3Parser;
import com.reprezen.kaizen.oasparser.model3.OpenApi3;
import com.reprezen.kaizen.oasparser.model3.Schema;
import java.io.File;

public class Main {

  private static final String RESOURCE_URI = "test.yaml";

  public static void main(String[] args) throws Exception {
    processModel(new File("src/main/resources/" + RESOURCE_URI));
  }

  private static void processModel(File modelFile) throws Exception {
    OpenApi3 model = new OpenApi3Parser().parse(modelFile, true);
    model.getValidationItems().forEach(validationItem ->
      System.out.println(validationItem.getSeverity() + ": " + validationItem.getMsg())
    );
    try {
      model.getPaths(false).values().forEach(path ->
        path.getOperations().values().forEach(operation ->
          operation.getResponses().values().forEach(response ->
            response.getContentMediaTypes().values().forEach(mediaType ->
              checkSchema(mediaType.getSchema())
            )
          )
        )
      );
    } catch (NullPointerException e) {
      System.out.println("Null pointer exception");
    }
  }

  private static void checkSchema(Schema schema) {
    int count = 0;
    while(schema != null && count < 100) {
      System.out.println(++count + ": Schema not null");
      schema = schema.getItemsSchema(true); // acts same if false or true
    }
  }
}

Apologies if I am just misunderstanding something or there's an easier way to see if the itemsSchema actually exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant