Forum Discussion

bernhardedler's avatar
bernhardedler
Frequent Visitor
4 years ago

use imported types as query param

is it possible to use an imported type (via importMapping) not only as the return type for an endpoint, but as its parameter as well?

 

for example:
my api.yaml

openapi: 3.0.3 
components: 
  schemas: 
    BossJobData: 
      type: object
[...] 
paths: 
  /jobcc/save: 
    post:
      operationId: save 
      parameters:
        - name: jobDataMap 
          required: true 
          in: query 
          schema: 
            $ref: '#/components/schemas/BossJobData' 
      responses: 
        '200': 
          description: OK 
          content: 
            application/json: 
              schema: 
                $ref: '#/components/schemas/BossJobData'



my pom.xml:

<build>
    <plugins>
        <plugin>
            <groupId>org.openapitools</groupId>
            <artifactId>openapi-generator-maven-plugin</artifactId>
            <version>5.0.1</version>
            <executions>
                <execution>
                    <id>generate</id>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <inputSpec>src/main/resources/api.yaml</inputSpec>
                        <language>jaxrs</language>
                        <generatorName>jaxrs-spec</generatorName>
                        <configOptions>
                            <sourceFolder>src/main/java</sourceFolder>
                            <useLoggingFeature>true</useLoggingFeature>
                            <useGzipFeature>true</useGzipFeature>
                            <hideGenerationTimestamp>true</hideGenerationTimestamp>
                            <interfaceOnly>true</interfaceOnly>
                        </configOptions>
                    </configuration>
                </execution>
            </executions>
            <configuration>
                <importMappings>
                    <importMapping>BossJobData=com.oebv.boss.shared.pojo.BossJobData</importMapping>
                </importMappings>
            </configuration>
        </plugin>
    </plugins>
</build>


and the resuling Java Code:

    @POST
    @Path("/save")
    @Produces({ "application/json" })
    @ApiOperation(value = "", notes = "", authorizations = {
        
        @Authorization(value = "basicAuth")
         }, tags={  })
    @ApiResponses(value = { 
        @ApiResponse(code = 200, message = "OK", response = com.oebv.boss.shared.pojo.BossJobData.class) })
    com.oebv.boss.shared.pojo.BossJobData save(@QueryParam("jobDataMap") @NotNull    Object jobDataMap);

So apparently
  a) the type is successfully imported

  b) the imported type can be used as return type
  c) it can't be used as parameter?

 

Am i missing something?
many thanks in advance,
bernhard 

No RepliesBe the first to reply