openapi-processor / openapi-processor-core

moved into openapi-processor-base
Apache License 2.0
7 stars 5 forks source link

validate openapi.yaml #77

Closed hauner closed 2 years ago

hauner commented 3 years ago

find errors in the openapi.yaml before the processor fails by validating the openapi.yaml with the json schema.

This is easy for a single file openapi.yml files.

Using jackson and json-schema-validator it basically works like this:

    val mapper = ObjectMapper(YAMLFactory())
    val tree = mapper.readTree(apiURL)
    // setup validator to use json schema in yaml format
    val factory = JsonSchemaFactory.Builder()
        .objectMapper(mapper)
        .defaultMetaSchemaURI(JsonMetaSchema.getV4().uri)
        .addMetaSchema(JsonMetaSchema.getV4())
        .build()

    val schema30 = URI("https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/schemas/v3.0/schema.yaml")
    val schema = factory.getSchema(schema30)
    val validation = schema.validate(tree)

Unfortunately it doesn't work with an openapi.yaml that $refs into other files. To validate it, all $refd files need to be merged into the openapi.yaml file.

I didn't find any easily usable java code to do this :-(

What it should do:

Experimental code seems to work on simple $refs.

hauner commented 3 years ago

validating of single files with $refs does not work. It does not report errors

The validator seems to ignore $refs.

hauner commented 2 years ago

internal openapi-processor/openapi-parser supports json schema validation with $refs.