Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python to Angular, issue while generating Dtos that contains nullable basic types ( str | None = None ) #5080

Open
leonandroid opened this issue Jan 6, 2025 · 0 comments

Comments

@leonandroid
Copy link

Describe the bug
The problem happens when trying to create an Angular Service from a Python WebApi.
The issue is presented specifically when a POST method receives a payload, which contains a native type like STR, but this type is expected to be nullable.

The issue is not present when the properties are not nullable.

More details:

This is the code in Python, the entity (payload) to use in the POST method.
It is very simple, but check on the conversation_Id that in particular is marked as nullable.

class Prompt(BaseModel):
    prompt: str
    conversation_id: str | None = None

This is the generated class for an Angular Service.
Instead of having a conversation_Id nullable, it creates a class for Conversation_Id, which is not expected, causing Angular to create instances for a simple value.

export class Conversation_id {

    [key: string]: any;

    init(_data?: any) {
        if (_data) {
            for (var property in _data) {
                if (_data.hasOwnProperty(property))
                    this[property] = _data[property];
            }
        }
    }

Version used
Always LATEST on every run.
call npm install -g nswag

To Reproduce

  1. In python API, create any post endpoint which receives a basic entity.
  2. Ensure the entity has a nullable basic type, like str.
  3. Generate the Service for angular with the following configuration provided int he section "Additional Context"
  4. Check the service generated, the conversationID instead of being a property, got created as a class.

Expected behavior

The conversationID should be created as a property, not a class.
The ConversationID should be nullable.
The Nullable phydantic model should be understood to consider nullables properly.

Additional context


{
  "runtime": "Net80",
  "defaultVariables": null,
  "documentGenerator": {
    "fromDocument": {
      "json": "",
      "url": "http://localhost:8000/openapi.json",
      "output": null
    }
  },
  "codeGenerators": {
    "openApiToTypeScriptClient": {
      "className": "{controller}Service",
      "moduleName": "",
      "namespace": "",
      "typeScriptVersion": 4.7,
      "template": "Angular",
      "promiseType": "Promise",
      "httpClass": "HttpClient",
      "withCredentials": false,
      "useSingletonProvider": false,
      "injectionTokenType": "InjectionToken",
      "rxJsVersion": 7.5,
      "dateTimeType": "Date",
      "nullValue": "Undefined",
      "generateClientClasses": true,
      "generateClientInterfaces": false,
      "generateOptionalParameters": false,
      "exportTypes": true,
      "wrapDtoExceptions": false,
      "exceptionClass": "ApiException",
      "clientBaseClass": null,
      "wrapResponses": false,
      "wrapResponseMethods": [],
      "generateResponseClasses": true,
      "responseClass": "SwaggerResponse",
      "protectedMethods": [],
      "configurationClass": null,
      "useTransformOptionsMethod": false,
      "useTransformResultMethod": false,
      "generateDtoTypes": true,
      "operationGenerationMode": "MultipleClientsFromFirstTagAndPathSegments",
      "markOptionalProperties": true,
      "generateCloneMethod": false,
      "typeStyle": "Class",
      "enumStyle": "Enum",
      "useLeafType": false,
      "classTypes": [],
      "extendedClasses": [],
      "extensionCode": null,
      "generateDefaultValues": true,
      "excludedTypeNames": [],
      "excludedParameterNames": [],
      "handleReferences": false,
      "generateConstructorInterface": false,
      "convertConstructorInterfaceData": false,
      "importRequiredTypes": true,
      "useGetBaseUrlMethod": false,
      "baseUrlTokenName": "API_BASE_URL",
      "queryNullValue": "",
      "inlineNamedDictionaries": false,
      "inlineNamedAny": false,
      "templateDirectory": null,
      "typeNameGeneratorType": null,
      "propertyNameGeneratorType": null,
      "enumNameGeneratorType": null,
      "serviceHost": null,
      "serviceSchemes": null,
      "output": "xxx/services/xxx.service.ts"
    }
  }
}

Add any other context about the problem here.

No further comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant