Skip to content
This repository was archived by the owner on Mar 16, 2025. It is now read-only.
This repository was archived by the owner on Mar 16, 2025. It is now read-only.

validate openapi.yaml #77

Closed
Closed

Description

@hauner

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:

  • add the file content to components:
    • in a nested x-key
    • in a nested file name based key so it is possible to know where the definitions com from
    • replace $ref to other file with $ref to `components/x-key/file-name#/type

Experimental code seems to work on simple $refs.

Activity

  1. self-assigned this
    on Aug 17, 2021
  2. added this to the next milestone on Aug 17, 2021
  3. hauner commented on Aug 22, 2021

    @hauner
    MemberAuthor

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

    • if there is an error in the referenced definition
    • if the $ref points to a non-existing definition

    The validator seems to ignore $refs.

  4. removed this from the next milestone on Aug 28, 2021
  5. hauner commented on Jun 1, 2022

    @hauner
    MemberAuthor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions