building OpenApiInteractionValidator from String payloads

Issue #189 resolved
Former user created an issue

com.atlassian.oai.validator.OpenApiInteractionValidator#createFor is supposed to be able to take "inline specification to use" ie. the actual specification as eg JSON string. But it never works given that OpenAPIParser sees OpenAPIV3Parser and/or OpenAPIV3Parser as Extensions.

com.atlassian.oai.validator.OpenApiInteractionValidator#loadApi expects that openAPIParser.readLocation returns null if it encounters problems. But instead, for example OpenAPIV3Parser will throw an exception if it is unable it use "location" as either URI or file path.

This is important, I a want to use swagger-request-validator as part of the web application to validate requests to its own APIs.

Caused by: 
com.atlassian.oai.validator.OpenApiInteractionValidator$ApiLoadException: Unable to load API spec from provided URL or payload:|?- attribute info is missing
    at com.atlassian.oai.validator.OpenApiInteractionValidator.loadApi(OpenApiInteractionValidator.java:155)
    at com.atlassian.oai.validator.OpenApiInteractionValidator.<init>(OpenApiInteractionValidator.java:123)
    at com.atlassian.oai.validator.OpenApiInteractionValidator.<init>(OpenApiInteractionValidator.java:45)
    at com.atlassian.oai.validator.OpenApiInteractionValidator$Builder.build(OpenApiInteractionValidator.java:426)

Comments (4)

  1. rafaldd

    I am sorry, the issue was elsewhere. I replaced passing URL to openap.json in the same web application:

    OpenApiInteractionValidator.createFor("http://localhost:8080/mywebapp/openapi.json").build()
    

    with code that creates the spec in OpenApiContextLocator.:

            String ctxId = ServletConfigContextUtils.getContextIdFromServletConfig(null);
            OpenApiContext ctx = OpenApiContextLocator.getInstance().getOpenApiContext(ctxId);
            OpenAPI oas = ctx.read();
            Info info = new Info();
            info.setTitle("anything");
            info.setVersion("1.0");
            oas.setInfo(info);
            return Json.pretty(oas);
    

    The problem (no idea why it happens) is that HTTP GET to "openapi.json" responds with JSON document containing "info" section based on static resource "openapi-configuration.json", but OpenAPI misses this element (This "info" section is not actually needed to validate requests coming to the application, but required to build OpenApiInteractionValidator)

    Please disregard or close.

  2. James Navin

    Thanks @10terabytes. I'll mark the issue as resolved. If you think there is a problem with the SRV please feel free to re-open.

  3. Log in to comment