How to avoid repetition between API interface and API contract in OpenAPI in Dropwizard Project

23 Views Asked by At

I have a backend dropwizard Java app where I define my APIs in my resource files. An example api looks like this:

@POST
@PATH("{userId}/doSomething")
@Produces(MediaType.APPLICATION_JSON)
public MyResponse doSomething(FrontendDoSomething req) {
  ...
}

I'm using the openapi-generator to generate a typescript client and typescript APIs that my frontend React web app can call. I end up having to redefine my API contract in my openapi.yaml file. The definition in yaml would look like

/resourcePath/{userId}/doSomething:
post:
   operationId: doSomething
   requestBody: 
       required: true
       content:
          application/json:
             schema:
               $ref: '#/components/schemas/FrontendDoSomething'
   responses:
     200:
       description: ...
       content:
         application/json:
           schema:
             $ref: '#/components/schemas/MyResponse'

How can I avoid repeating myself? It feels like I am mostly repeating my API contract in yaml.

0

There are 0 best solutions below