OpenAPI Generator and services

I have used the OpenAPI Generator to consume a swagger definition and while it creates the classes, it does not extract the service operations.

Any idea why?

Can you please provide more detailed information? A Swagger definition doesn't make a distinction between "classes" and "service operations". Those are XData specific concepts.

Sorry, services was the wrong term. I should have said Endpoints.

When I import the PetStore API I get an interface and object that implements the endpoints for the calls. The 2 APIs I am trying to import create the objects but not the endpoint interface/object methods.

So PetStore gives me as one example

IPetService = interface(IInvokable)
    ['{D12C0458-920F-4A50-99BB-7E31A1D926D7}']
    /// <summary>
    /// uploads an image
    /// </summary>
    /// <param name="PetId">
    /// ID of pet to update
    /// </param>
    /// <param name="AdditionalMetadata">
    /// Additional data to pass to server
    /// </param>
    /// <param name="&File">
    /// file to upload
    /// </param>
    function UploadFile(PetId: Int64; AdditionalMetadata: string; &File: TBytes): TApiResponse;
    /// <summary>
    /// Update an existing pet
    /// </summary>
    /// <param name="Body">
    /// Pet object that needs to be added to the store
    /// </param>
    procedure UpdatePet(Body: TPet);
    /// <summary>
    /// Add a new pet to the store
    /// </summary>
    /// <param name="Body">
    /// Pet object that needs to be added to the store
    /// </param>
    procedure AddPet(Body: TPet);
    /// <summary>
    /// Finds Pets by status
    /// </summary>
    /// <param name="Status">
    /// Status values that need to be considered for filter
    /// </param>
    /// <remarks>
    /// Multiple status values can be provided with comma separated strings
    /// </remarks>
    function FindPetsByStatus(Status: stringArray): TPetList;
    /// <summary>
    /// Finds Pets by tags
    /// </summary>
    /// <param name="Tags">
    /// Tags to filter by
    /// </param>
    /// <remarks>
    /// Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
    /// </remarks>
    function FindPetsByTags(Tags: stringArray): TPetList;
    /// <summary>
    /// Find pet by ID
    /// </summary>
    /// <param name="PetId">
    /// ID of pet to return
    /// </param>
    /// <remarks>
    /// Returns a single pet
    /// </remarks>
    function GetPetById(PetId: Int64): TPet;
    /// <summary>
    /// Updates a pet in the store with form data
    /// </summary>
    /// <param name="PetId">
    /// ID of pet that needs to be updated
    /// </param>
    /// <param name="Name">
    /// Updated name of the pet
    /// </param>
    /// <param name="Status">
    /// Updated status of the pet
    /// </param>
    procedure UpdatePetWithForm(PetId: Int64; Name: string; Status: string);
    /// <summary>
    /// Deletes a pet
    /// </summary>
    /// <param name="PetId">
    /// Pet id to delete
    /// </param>
    procedure DeletePet(ApiKey: string; PetId: Int64);
  end;

And the ones I import give

  IColl8Client = interface(IRestClient)
  end;
  
  TColl8Client = class(TCustomRestClient, IColl8Client)
  public
    constructor Create;
  end;

I don't know, maybe the endpoints in your Swagger definition are not supported by the generator - for example, they don't return JSON.

It all looks valid. It is Swagger 2.0 - here is an example of the paths

"paths": {
    "/shipping/createLabel": {
      "post": {
        "tags": [
          "labelling"
        ],
        "description": "",
        "operationId": "createLabel",
        "parameters": [
          {
            "in": "body",
            "name": "body",
            "required": true,
            "schema": {
              "$ref": "#/definitions/CreateLabelRequest"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Successfully created label",
            "schema": {
              "$ref": "#/definitions/CreateLabelResponse"
            }
          },
          "400": {
            "description": "The request body was incorrectly structured and could not be processed"
          },
          "401": {
            "description": "The request's `X-API-Key` header was not present, or was malformed"
          },
          "403": {
            "description": "The request's `X-API-Key` header contained a token that does not have access to this API"
          },
          "500": {
            "description": "An unexpected error occurred processing the request",
            "schema": {
              "$ref": "#/definitions/Error"
            }
          }
        },
        "x-swagger-router-controller": "Labelling"
      }
    }
  }

It is possible to provide the full Swagger document so we can at least try to reproduce it at our side?

I'll send it to you as a message

Thanks for the files. In one case, the Swagger document didn't have the OperationId filled for the endpoints. In the second case, the Consumes tag was empty for the endpoints.

The two issues have been fixed now in version 1.1.3:

For further support on this, you can also alternatively create an issue directly in the GitHub repository.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.