OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.9k stars 6.58k forks source link

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

Open maxl2287 opened 9 months ago

maxl2287 commented 9 months ago
Description

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

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
rmueller83 commented 5 months ago

Duplicate of 14053?