smallrye / smallrye-open-api

SmallRye implementation of Eclipse MicroProfile OpenAPI
Apache License 2.0
113 stars 87 forks source link

Json schema support in $refs #1747

Closed AlanMasciangelo closed 4 months ago

AlanMasciangelo commented 4 months ago

Does this project support dereferencing remote or uri $refs? For example, I want to define my schema via a JSON schema definition and have that dereferenced into the final openapi output.

MikeEdgar commented 4 months ago

Hi @AlanMasciangelo , it's not support directly, but you could do something like this with an OASFilter:

class SchemaDereferenceFilter implements OASFilter {
    public Schema filterSchema(Schema schema) {
        if (schema.getRef() == null) {
            return schema;
        }

        String remoteSchema = null; // fetch the schema from the value in schema.getRef()
        // the schema must be JSON
        return OpenApiParser.parseSchema(remoteSchema);
    }
}
MikeEdgar commented 4 months ago

@AlanMasciangelo did you give this a try and does it seem workable for you?

AlanMasciangelo commented 4 months ago

@MikeEdgar I haven't had a chance to test yet but yes this looks like it will work fine.