google / gnostic

A compiler for APIs described by the OpenAPI Specification with plugins for code generation and other API support tasks.
Apache License 2.0
2.08k stars 246 forks source link

Exclude proto message fields from OpenAPI spec #265

Open grizzlybearer opened 2 years ago

grizzlybearer commented 2 years ago

Is it possible to exclude certain fields defined in a protobuf and its corresponding graph from the OpenAPI spec generated by https://github.com/google/gnostic/tree/master/apps/protoc-gen-openapi ?

Say the proto is

Message SomeProto {
     string field_1 = 1;
     AnotherProto field_2 = 2; // exclude this
}
// this proto should not be included in the OpenAPI spec
Message AnotherProto {
   SomeMoreDepProto field = 1;
    ...
}

Currently, the OpenAPI spec defines all of these protos under the components->schemas

components:
    schemas:
        SomeProto:
            properties:
                field_1:
                    type: string
                    description: ''
                field_2:
                    ref: $ref: '#/components/schemas/AnotherProto'
        AnotherProto:
            properties:
                field_1:
                    ref: $ref: '#/components/schemas/SomeMoreDepProto'

AnotherProto and SomeMoreDepProto are internal protos that I cannot expose.

I need the OpenAPI spec to thus be

components:
    schemas:
        SomeProto:
            properties:
                field_1:
                    type: string
                    description: ''
grizzlybearer commented 1 year ago

Tagging active members to seek attention - @timburks @ppaanngggg

ppaanngggg commented 1 year ago

as I know, it is impossible now