ballerina-platform / ballerina-library

The Ballerina Library
https://ballerina.io/learn/api-docs/ballerina/
Apache License 2.0
136 stars 64 forks source link

OpenAPI generated does not have all types #6980

Open shirolk opened 2 months ago

shirolk commented 2 months ago

Description: In the types definition that is used for a Ballerina service there is a type which is a union of constants. This type is part of a struct.

public const RESOURCE_KIND_ENVIRONMENT = "Environment";
public const RESOURCE_KIND_PROJECT = "Project";
public const RESOURCE_KIND_COMPONENT = "Component";
public const RESOURCE_KIND_BUILD = "Build";
public const RESOURCE_KIND_DEPLOYABLE_ARTIFACT = "DeployableArtifact";
public const RESOURCE_KIND_DEPLOYMENT = "Deployment";

public type ResourceKind RESOURCE_KIND_ENVIRONMENT|RESOURCE_KIND_PROJECT|RESOURCE_KIND_COMPONENT|RESOURCE_KIND_BUILD|
    RESOURCE_KIND_DEPLOYABLE_ARTIFACT|RESOURCE_KIND_DEPLOYMENT;

public type Environment record {
    string apiVersion;
    RESOURCE_KIND_ENVIRONMENT kind = RESOURCE_KIND_ENVIRONMENT;
    Metadata metadata;
    EnvironmentSpec spec;
    EnvironmentStatus status?;
};

When the OpenAPI tool is used to generate the OpenAPI Spec this type is omitted. bal openapi -i service.bal

Later this spec is used to generate a client and as a result the resulting types have a missing field bal openapi -i -o --mode client

public type Environment record {
    string apiVersion;
    Metadata metadata;
    EnvironmentSpec spec;
    EnvironmentStatus status?;
};

Suggested Labels (optional): module/openapi-tools Area/OpenapiToBallerina Area/BallerinaToOpenapi

lnash94 commented 2 months ago

Currently, the tool won't support the literal value, the tool will support the defined types. In the above scenarios is there a particular reason to add a kind as a literal value, if possible to have a kind with ResourceKind we will map the kind type to the given type.

public type Environment record {
    string apiVersion;
    ResourceKind kind = RESOURCE_KIND_ENVIRONMENT;
    Metadata metadata;
    EnvironmentSpec spec;
    EnvironmentStatus status?;
};
TharmiganK commented 2 months ago

There are two issues here:

  1. The constant value expression is not yet supported for the default value mapping. Only the following expression types are supported: https://github.com/ballerina-platform/openapi-tools/blob/c2785574f50aed737bfd99d23d810a0a6cf37956/ballerina-to-openapi/src/main/java/io/ballerina/openapi/service/mapper/utils/MapperCommonUtils.java#L115
  2. The singleton type is not yet supported in the OpenAPI mapping. The currently supported basic types given in the spec: https://github.com/ballerina-platform/openapi-tools/blob/master/docs/ballerina-to-oas/spec/spec.md#the-ballerina-type-to-schema-mapping