Forum Discussion

pranavkevadiya's avatar
pranavkevadiya
New Member
3 years ago

How to generate a big single schema object using swagger v3 annotations

Hi community,

 

I am using swagger-annotations v3 and micronaut-openapi to generate open-api specs in my project. My problem statement is simple but I am not yet able to achieve it. 

 

I have a nested object structure in my request/response body, for which swagger will generate a schema in OpenAPI specs. However, I don't want to create all those granular schema objects but want only one big object. How can I achieve that?

 

Example:

class A {
   String a;
   String b;
   ClassB classBObject;
}

class B {
  String c;
  String d;
}

 

 

When swagger generates OpenAPI specs, it generates 2 schema definitions "A" and "B". However, I would only need one definition but the "B" remains an nested element under schema "A"

Example:

A:
      required:
      - a
      - b
      - classBObject
      type: object
      properties:
        a:
          type: string
        b:
          type: string
        classBObject:
          type: object
          properties:
           c:
             type: string
           d:
             type: string
No RepliesBe the first to reply