OpenAPITools / OpenAPITools/openapi-generator

[BUG] [RESTTEMPLATE] When two 2xx-responses in the YAML then only one response is used for the operation-method

Open
#17,766 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

I have for the provided /subscriptions-endpoint two 2xx-responses:

  • 200 OK with response MonitoringEventReport
  • 201 CREATED with response MonitoringEventSubscription

But the generated Api contains only the POST with a response-type of MonitoringEventReport .

But I need to have both, so that it could be a 200 response with MonitoringEventReport or a 201 response with MonitoringEventSubscription

ℹ️ I am not allowed to edit this specification. ℹ️

Generated API-class
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2024-02-01T15:33:28.126276900+01:00[Europe/Berlin]")
@Component("com.test.network.api.Class5GcEpcApi")
public class Class5GcEpcApi {
    private ApiClient apiClient;

    public Class5GcEpcApi() {
        this(new ApiClient());
    }

    @Autowired
    public Class5GcEpcApi(ApiClient apiClient) {
        this.apiClient = apiClient;
    }

    public ApiClient getApiClient() {
        return apiClient;
    }

    public void setApiClient(ApiClient apiClient) {
        this.apiClient = apiClient;
    }

    /**
     * Creates a new subscription resource for monitoring event notification
     * 
     * <p><b>201</b> - Created (Successful creation of subscription)
     * <p><b>200</b> - The operation is successful and immediate report is included.
     * <p><b>400</b> - Bad request
     * <p><b>401</b> - Unauthorized
     * <p><b>403</b> - Forbidden
     * <p><b>404</b> - Not Found
     * <p><b>411</b> - Length Required
     * <p><b>413</b> - Payload Too Large
     * <p><b>415</b> - Unsupported Media Type
     * <p><b>429</b> - Too Many Requests
     * <p><b>500</b> - Internal Server Error
     * <p><b>503</b> - Service Unavailable
     * <p><b>0</b> - Generic Error
     * @param scsAsId Identifier of the SCS/AS (required)
     * @param monitoringEventSubscription Subscription for notification about monitoring event (required)
     * @return MonitoringEventReport
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public MonitoringEventReport scsAsIdSubscriptionsPost(String scsAsId, MonitoringEventSubscription monitoringEventSubscription) throws RestClientException {
        return scsAsIdSubscriptionsPostWithHttpInfo(scsAsId, monitoringEventSubscription).getBody();
    }

    /**
     * Creates a new subscription resource for monitoring event notification
     * 
     * <p><b>201</b> - Created (Successful creation of subscription)
     * <p><b>200</b> - The operation is successful and immediate report is included.
     * <p><b>400</b> - Bad request
     * <p><b>401</b> - Unauthorized
     * <p><b>403</b> - Forbidden
     * <p><b>404</b> - Not Found
     * <p><b>411</b> - Length Required
     * <p><b>413</b> - Payload Too Large
     * <p><b>415</b> - Unsupported Media Type
     * <p><b>429</b> - Too Many Requests
     * <p><b>500</b> - Internal Server Error
     * <p><b>503</b> - Service Unavailable
     * <p><b>0</b> - Generic Error
     * @param scsAsId Identifier of the SCS/AS (required)
     * @param monitoringEventSubscription Subscription for notification about monitoring event (required)
     * @return ResponseEntity&lt;MonitoringEventReport&gt;
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public ResponseEntity<MonitoringEventReport> scsAsIdSubscriptionsPostWithHttpInfo(String scsAsId, MonitoringEventSubscription monitoringEventSubscription) throws RestClientException {
        Object localVarPostBody = monitoringEventSubscription;
        
        // verify the required parameter 'scsAsId' is set
        if (scsAsId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'scsAsId' when calling scsAsIdSubscriptionsPost");
        }
        
        // verify the required parameter 'monitoringEventSubscription' is set
        if (monitoringEventSubscription == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'monitoringEventSubscription' when calling scsAsIdSubscriptionsPost");
        }
        
        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("scsAsId", scsAsId);

        final MultiValueMap<String, String> localVarQueryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders localVarHeaderParams = new HttpHeaders();
        final MultiValueMap<String, String> localVarCookieParams = new LinkedMultiValueMap<String, String>();
        final MultiValueMap<String, Object> localVarFormParams = new LinkedMultiValueMap<String, Object>();

        final String[] localVarAccepts = { 
            "application/json", "application/problem+json"
         };
        final List<MediaType> localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
        final String[] localVarContentTypes = { 
            "application/json"
         };
        final MediaType localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);

        String[] localVarAuthNames = new String[] {  };

        ParameterizedTypeReference<MonitoringEventReport> localReturnType = new ParameterizedTypeReference<MonitoringEventReport>() {};
        return apiClient.invokeAPI("/{scsAsId}/subscriptions", HttpMethod.POST, uriVariables, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAccept, localVarContentType, localVarAuthNames, localReturnType);
    }
}
openapi-generator version

7.2.0

OpenAPI declaration file content or url
paths:
  /{scsAsId}/subscriptions:
    post:
      summary: Creates a new subscription resource for monitoring event notification
      tags:
      - 5GC/EPC
      parameters:
      - name: scsAsId
        in: path
        description: Identifier of the SCS/AS
        required: true
        schema:
          type: string
      requestBody:
        description: Subscription for notification about monitoring event
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/MonitoringEventSubscription'
      responses:
        "201":
          description: Created (Successful creation of subscription)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MonitoringEventSubscription'
          headers:
            Location:
              description: "Contains the URI of the newly created resource"
              required: true
              schema:
                type: string
        "200":
          description: The operation is successful and immediate report is included.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MonitoringEventReport'
                createSubscriptionResponse:
                  summary: Create response 200 for a new subscription
                  value:
                    externalId: "test@test.com"
                    monitoringType: "LOSS_OF_CONNECTIVITY"
                    lossOfConnectReason: 0
Generation Details
 <build>
    <plugins>
      <plugin>
        <groupId>org.openapitools</groupId>
        <artifactId>openapi-generator-maven-plugin</artifactId>
        <version>7.2.0</version>
        <executions>
          <execution>
            <id>client</id>
            <goals>
              <goal>generate</goal>
            </goals>
            <configuration>
              <inputSpec>${project.basedir}/src/main/resources/spce.yaml</inputSpec>
              <generatorName>java</generatorName>
              <library>resttemplate</library>
              <apiPackage>com.test.network.api</apiPackage>
              <invokerPackage>com.test.network.api</invokerPackage>
              <modelPackage>com.test.network.api.model</modelPackage>
              <configOptions>
                <additionalModelTypeAnnotations>
                  @com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)
                </additionalModelTypeAnnotations>
                <useJakartaEe>true</useJakartaEe>
                <generateClientAsBean>true</generateClientAsBean>
              </configOptions>
              <generateApiTests>false</generateApiTests>
              <generateModelTests>false</generateModelTests>
            </configuration>
          </execution>
          <execution>
            <id>server</id>
            <goals>
              <goal>generate</goal>
            </goals>
            <configuration>
              <inputSpec>${project.basedir}/src/main/resources/spec.yaml</inputSpec>
              <generatorName>spring</generatorName>
              <apiPackage>com.test.network.api.notifications</apiPackage>
              <modelPackage>com.test.network.api.model</modelPackage>
              <supportingFilesToGenerate>ApiUtil.java</supportingFilesToGenerate>
              <configOptions>
                <useSpringBoot3>true</useSpringBoot3>
                <delegatePattern>true</delegatePattern>
                <useJakartaEe>true</useJakartaEe>
              </configOptions>
              <environmentVariables>
                <apis>notifications</apis>
              </environmentVariables>
              <openapiNormalizer>
                SIMPLIFY_ANYOF_STRING_AND_ENUM_STRING=true
              </openapiNormalizer>
              <generateApiTests>false</generateApiTests>
              <generateModelTests>false</generateModelTests>
            </configuration>
          </execution>
        </executions>
      </plugin>
Suggest a fix

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the OpenAPI declaration for /{scsAsId}/subscriptions and the Maven configuration using generatorName java and library resttemplate. Compare the two declared 2xx responses with the generated Class5GcEpcApi; done means the generated client exposes both MonitoringEventReport and MonitoringEventSubscription response types.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.