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

OpenAPIParser or OpenAPIV3Parser could not parse petstore openapi 3.1 spec #2115

Closed
rajakumar17 opened this issue Aug 9, 2024 · 2 comments
Closed

Comments

@rajakumar17
Copy link

I am using swagger parser to parse various openapi specifications. OAS2.0 and 3.0 specifications works fine. However, OAS3.1 specification fails to parse.

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

Code sample

        ParseOptions parseOptions = new ParseOptions();
        parseOptions.setResolve(true);
        parseOptions.setResolveFully(true);
        SwaggerParseResult result = new OpenAPIParser().readLocation("https://petstore31.swagger.io/api/v31/openapi.json", null, parseOptions);
        OpenAPI openAPI = result.getOpenAPI();

        if (result.getMessages() != null) {
            result.getMessages()
                  .forEach(System.err::println); // validation errors and warnings
        }

        if (openAPI != null) {
            final Map<String, Schema> schemas = openAPI.getComponents()
                                                       .getSchemas();
            schemas.entrySet()
                   .stream()
                   .forEach(this::printSchema);
        }

Exception

java.io.FileNotFoundException: https://petstore31.swagger.io/components/schemas/category
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?]
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) ~[?:?]
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:?]
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) ~[?:?]
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480) ~[?:?]
at java.base/sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:2048) ~[?:?]
at java.base/sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:2043) ~[?:?]
at java.base/java.security.AccessController.doPrivileged(AccessController.java:569) ~[?:?]
at java.base/sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:2042) ~[?:?]
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1609) ~[?:?]
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1589) ~[?:?]
at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:224) ~[?:?]
at io.swagger.v3.parser.util.RemoteUrl.urlToString(RemoteUrl.java:155) ~[swagger-parser-v3-2.1.22.jar:2.1.22]
at io.swagger.v3.parser.reference.ReferenceVisitor.readHttp(ReferenceVisitor.java:200) ~[swagger-parser-v3-2.1.22.jar:2.1.22]
at io.swagger.v3.parser.reference.Visitor.readURI(Visitor.java:82) ~[swagger-parser-v3-2.1.22.jar:2.1.22]
at io.swagger.v3.parser.reference.ReferenceVisitor.parse(ReferenceVisitor.java:305) ~[swagger-parser-v3-2.1.22.jar:2.1.22]
at io.swagger.v3.parser.reference.ReferenceVisitor.resolveSchemaRef(ReferenceVisitor.java:237) ~[swagger-parser-v3-2.1.22.jar:2.1.22]
at io.swagger.v3.parser.reference.ReferenceVisitor.visitSchema(ReferenceVisitor.java:141) ~[swagger-parser-v3-2.1.22.jar:2.1.22]
at io.swagger.v3.parser.reference.OpenAPI31Traverser.traverseSchema(OpenAPI31Traverser.java:790) ~[swagger-parser-v3-2.1.22.jar:2.1.22]
at io.swagger.v3.parser.reference.OpenAPI31Traverser.traverseSchema(OpenAPI31Traverser.java:856) ~[swagger-parser-v3-2.1.22.jar:2.1.22]
at io.swagger.v3.parser.reference.OpenAPI31Traverser.traverseSchemaMap(OpenAPI31Traverser.java:946) ~[swagger-parser-v3-2.1.22.jar:2.1.22]
at io.swagger.v3.parser.reference.OpenAPI31Traverser.traverseSchema(OpenAPI31Traverser.java:800) ~[swagger-parser-v3-2.1.22.jar:2.1.22]
at io.swagger.v3.parser.reference.ReferenceVisitor.resolveSchemaRef(ReferenceVisitor.java:262) ~[swagger-parser-v3-2.1.22.jar:2.1.22]
at io.swagger.v3.parser.reference.ReferenceVisitor.visitSchema(ReferenceVisitor.java:141) ~[swagger-parser-v3-2.1.22.jar:2.1.22]
at io.swagger.v3.parser.reference.OpenAPI31Traverser.traverseSchema(OpenAPI31Traverser.java:790) ~[swagger-parser-v3-2.1.22.jar:2.1.22]
at io.swagger.v3.parser.reference.OpenAPI31Traverser.traverseMediaType(OpenAPI31Traverser.java:603) ~[swagger-parser-v3-2.1.22.jar:2.1.22]
at io.swagger.v3.parser.reference.OpenAPI31Traverser.traverseMap(OpenAPI31Traverser.java:933) ~[swagger-parser-v3-2.1.22.jar:2.1.22]
at io.swagger.v3.parser.reference.OpenAPI31Traverser.traverseRequestBody(OpenAPI31Traverser.java:346) ~[swagger-parser-v3-2.1.22.jar:2.1.22]
at io.swagger.v3.parser.reference.OpenAPI31Traverser.traverseOperation(OpenAPI31Traverser.java:229) ~[swagger-parser-v3-2.1.22.jar:2.1.22]
at io.swagger.v3.parser.reference.OpenAPI31Traverser.traversePathItem(OpenAPI31Traverser.java:399) ~[swagger-parser-v3-2.1.22.jar:2.1.22]
at io.swagger.v3.parser.reference.OpenAPI31Traverser.traverseMap(OpenAPI31Traverser.java:933) ~[swagger-parser-v3-2.1.22.jar:2.1.22]
at io.swagger.v3.parser.reference.OpenAPI31Traverser.traversePaths(OpenAPI31Traverser.java:197) ~[swagger-parser-v3-2.1.22.jar:2.1.22]
at io.swagger.v3.parser.reference.OpenAPI31Traverser.traverseOpenApi(OpenAPI31Traverser.java:124) ~[swagger-parser-v3-2.1.22.jar:2.1.22]
at io.swagger.v3.parser.reference.OpenAPI31Traverser.traverse(OpenAPI31Traverser.java:65) ~[swagger-parser-v3-2.1.22.jar:2.1.22]
at io.swagger.v3.parser.reference.OpenAPIDereferencer31.dereference(OpenAPIDereferencer31.java:74) ~[swagger-parser-v3-2.1.22.jar:2.1.22]
at io.swagger.v3.parser.OpenAPIV3Parser.resolve(OpenAPIV3Parser.java:227) ~[swagger-parser-v3-2.1.22.jar:2.1.22]
at io.swagger.v3.parser.OpenAPIV3Parser.readContents(OpenAPIV3Parser.java:183) ~[swagger-parser-v3-2.1.22.jar:2.1.22]
at io.swagger.v3.parser.OpenAPIV3Parser.readLocation(OpenAPIV3Parser.java:97) ~[swagger-parser-v3-2.1.22.jar:2.1.22]
at io.swagger.parser.OpenAPIParser.readLocation(OpenAPIParser.java:16) ~[swagger-parser-2.1.22.jar:2.1.22]
at com.informatica.cai.catalog.scanner.openapi.OpenAPISpecParserTest.testOpenAPI(OpenAPISpecParserTest.java:36) ~[test-classes/:?]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[?:?]
at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:728) ~[junit-platform-commons-1.10.2.jar:1.10.2]
at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60) ~[junit-jupiter-engine-5.10.2.jar:5.10.2]
at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131) ~[junit-jupiter-engine-5.10.2.jar:5.10.2]
at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:156) ~[junit-jupiter-engine-5.10.2.jar:5.10.2]
at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:147) ~[junit-jupiter-engine-5.10.2.jar:5.10.2]
at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:86) ~[junit-jupiter-engine-5.10.2.jar:5.10.2]
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(InterceptingExecutableInvoker.java:103) ~[junit-jupiter-engine-5.10.2.jar:5.10.2]
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.lambda$invoke$0(InterceptingExecutableInvoker.java:93) ~[junit-jupiter-engine-5.10.2.jar:5.10.2]
at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106) ~[junit-jupiter-engine-5.10.2.jar:5.10.2]
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64) ~[junit-jupiter-engine-5.10.2.jar:5.10.2]
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45) ~[junit-jupiter-engine-5.10.2.jar:5.10.2]
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37) ~[junit-jupiter-engine-5.10.2.jar:5.10.2]
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:92) ~[junit-jupiter-engine-5.10.2.jar:5.10.2]
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:86) ~[junit-jupiter-engine-5.10.2.jar:5.10.2]
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:218) ~[junit-jupiter-engine-5.10.2.jar:5.10.2]
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) ~[junit-platform-engine-1.10.2.jar:1.10.2]
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:214) ~[junit-jupiter-engine-5.10.2.jar:5.10.2]
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:139) ~[junit-jupiter-engine-5.10.2.jar:5.10.2]
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:69) ~[junit-jupiter-engine-5.10.2.jar:5.10.2]
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151) ~[junit-platform-engine-1.10.2.jar:1.10.2]
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) ~[junit-platform-engine-1.10.2.jar:1.10.2]
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141) ~[junit-platform-engine-1.10.2.jar:1.10.2]
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137) ~[junit-platform-engine-1.10.2.jar:1.10.2]
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139) ~[junit-platform-engine-1.10.2.jar:1.10.2]
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) ~[junit-platform-engine-1.10.2.jar:1.10.2]
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138) ~[junit-platform-engine-1.10.2.jar:1.10.2]
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95) ~[junit-platform-engine-1.10.2.jar:1.10.2]

@rajakumar17
Copy link
Author

Category object is part of the same specification json. This is looking at the wrong location.

@frantuma
Copy link
Member

This is related to OAS 3.1 dereference with $id involved, as in OAS 3.1 petstore, and is fixed by #2132 (and petstore 3.1 slight update)

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

2 participants