Skip to content

[BUG] Callback request and response not being flattened to InlineObjects #3397

Closed
@lwlee2608

Description

@lwlee2608

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description
openapi-generator version

3.3.4

OpenAPI declaration file content or url

When trying to run codegein against the following OpenApi3 yaml snippet:

 /ue-contexts/{ueContextId}/n1-n2-messages/subscriptions:
    post:
      summary: Namf_Communication N1N2 Message Subscribe (UE Specific) service Operation
      tags:
        - N1N2 Subscriptions Collection for Individual UE Contexts (Document)
      operationId: N1N2MessageSubscribe
      parameters:
        - name: ueContextId
          in: path
          description: UE Context Identifier
          required: true
          schema:
            type: string
            pattern: '^(5g-guti-[0-9]{5,6}[0-9a-fA-F]{14}|imsi-[0-9]{5,15}|nai-.+|imei-[0-9]{15}|imeisv-[0-9]{16}|.+)$'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UeN1N2InfoSubscriptionCreateData'
        required: true
      responses:
        '201':
          description: N1N2 Message Subscription successfully created.
          headers:
            Location:
              description: 'Contains the URI of the newly created resource, according to the structure: {apiRoot}/namf-comm/v1/{ueContextId}/n1-n2-messages/subscriptions/{subscriptionId}'
              required: true
              schema:
                type: string
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UeN1N2InfoSubscriptionCreatedData'
        '400':
          $ref: 'TS29571_CommonData.yaml#/components/responses/400'
        '411':
          $ref: 'TS29571_CommonData.yaml#/components/responses/411'
        '413':
          $ref: 'TS29571_CommonData.yaml#/components/responses/413'
        '415':
          $ref: 'TS29571_CommonData.yaml#/components/responses/415'
        '429':
          $ref: 'TS29571_CommonData.yaml#/components/responses/429'
        '500':
          $ref: 'TS29571_CommonData.yaml#/components/responses/500'
        '503':
          $ref: 'TS29571_CommonData.yaml#/components/responses/503'
        default:
          description: Unexpected error
      callbacks:
        onN1N2MessageNotify:
          '{$request.body#/n1NotifyCallbackUri}':
            post:
              summary: Namf_Communication N1 Message Notify service Operation
              tags:
                - N1 Message Notify
              operationId: N1MessageNotify
              requestBody:
                description: N1 Message Notification
                content:
                  multipart/related:  # message with binary body part(s)
                    schema:
                      type: object
                      properties: # Request parts
                        jsonData:
                          $ref: '#/components/schemas/N1MessageNotification'
                        binaryDataN1Message:
                          type: string
                          format: binary
                    encoding:
                      jsonData:
                        contentType:  application/json
                      binaryDataN1Message:
                        contentType:  application/vnd.3gpp.5gnas
                        headers:
                          Content-Id:
                            schema:
                              type: string
              responses:
                '204':
                  description: Expected response to a successful callback processing
                '400':
                  $ref: 'TS29571_CommonData.yaml#/components/responses/400'
                '403':
                  $ref: 'TS29571_CommonData.yaml#/components/responses/403'
                '411':
                  $ref: 'TS29571_CommonData.yaml#/components/responses/411'
                '413':
                  $ref: 'TS29571_CommonData.yaml#/components/responses/413'
                '415':
                  $ref: 'TS29571_CommonData.yaml#/components/responses/415'
                '429':
                  $ref: 'TS29571_CommonData.yaml#/components/responses/429'
                '500':
                  $ref: 'TS29571_CommonData.yaml#/components/responses/500'
                '503':
                  $ref: 'TS29571_CommonData.yaml#/components/responses/503'
          '{$request.body#/n2NotifyCallbackUri}':
            post:
              summary: Namf_Communication N2 Info Notify (UE Specific) service Operation
              tags:
                - N2 Info Notify
              operationId: N2InfoNotify
              requestBody:
                description: UE Specific N2 Informaiton Notification
                content:
                  multipart/related:  # message with binary body part(s)
                    schema:
                      type: object
                      properties: # Request parts
                        jsonData:
                          $ref: '#/components/schemas/N2InformationNotification'
                        binaryDataN1Message:
                          type: string
                          format: binary
                        binaryDataN2Information:
                          type: string
                          format: binary
                    encoding:
                      jsonData:
                        contentType:  application/json
                      binaryDataN1Message:
                        contentType:  application/vnd.3gpp.5gnas
                        headers:
                          Content-Id:
                            schema:
                              type: string
                      binaryDataN2Information:
                        contentType:  application/vnd.3gpp.ngap
                        headers:
                          Content-Id:
                            schema:
                              type: string
              responses:
                '204':
                  description: Expected response to a successful callback processing
                '400':
                  $ref: 'TS29571_CommonData.yaml#/components/responses/400'
                '411':
                  $ref: 'TS29571_CommonData.yaml#/components/responses/411'
                '413':
                  $ref: 'TS29571_CommonData.yaml#/components/responses/413'
                '415':
                  $ref: 'TS29571_CommonData.yaml#/components/responses/415'
                '429':
                  $ref: 'TS29571_CommonData.yaml#/components/responses/429'
                '500':
                  $ref: 'TS29571_CommonData.yaml#/components/responses/500'
                '503':
                  $ref: 'TS29571_CommonData.yaml#/components/responses/503'

Our expected generated code should look like

public interface N1n2messagesubscribeCallbackApi extends Api {
    
    public static final String BASE_PATH = "n1n2messagesubscribe-callback";
            Single<Response<Void>> n1MessageNotify(String requestURI, InlineObject1 inlineObject1, FlowContext ctx, MultiMap requestHeaders);
            Single<Response<Void>> n2InfoNotify(String requestURI, InlineObject2 inlineObject2, FlowContext ctx, MultiMap requestHeaders);

}

However the inline object is not defined. InlineObject become UNKNOWN_BASE_TYPE instead.
generated java code:

public interface N1n2messagesubscribeCallbackApi extends Api {
    
    public static final String BASE_PATH = "n1n2messagesubscribe-callback";
            Single<Response<Void>> n1MessageNotify(String requestURI, UNKNOWN_BASE_TYPE UNKNOWN_BASE_TYPE, FlowContext ctx, MultiMap requestHeaders);
            Single<Response<Void>> n2InfoNotify(String requestURI, UNKNOWN_BASE_TYPE UNKNOWN_BASE_TYPE, FlowContext ctx, MultiMap requestHeaders);

}
Command line used for generation

No, using the openapi-generator-maven-plugin

Steps to reproduce

maven generate-sources command

Related issues/PRs

#372

Suggest a fix

in InlineModelResolver.java Include callback-operations to be flatten:

    private void flattenPaths(OpenAPI openAPI) {
        Paths paths = openAPI.getPaths();
        if (paths == null) {
            return;
        }

        for (String pathname : paths.keySet()) {
            PathItem path = paths.get(pathname);
            List<Operation> operations = new ArrayList<>(path.readOperations());

            // Include callback operation as well
            for (Operation operation : path.readOperations()) {
                Map<String, Callback> callbacks = operation.getCallbacks();
                if (callbacks != null) {
                    operations.addAll(callbacks.values().stream()
                            .flatMap(callback -> callback.values().stream())
                            .flatMap(pathItem -> pathItem.readOperations().stream())
                            .collect(Collectors.toList()));
                }
            }

            for (Operation operation : operations) {
                flattenRequestBody(openAPI, pathname, operation);
                flattenParameters(openAPI, pathname, operation);
                flattenResponses(openAPI, pathname, operation);
            }
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions