An issue encountered with NSwag in TypeScript-Angular involving enum property names and DateTime data type

Encountering issues with generating enums and DateTime attributes using Nswag and OpenApi.

First concern is regarding the Enums generation, aiming for a specific format like:

export enum BillboardType {
    BB = 0,
    BB18 = 1,
    Direction = 2,
    Banner = 3
}

However, the outcome from open api cli ends up being:

export enum BillboardType {
    NUMBER_0 = 0,
    NUMBER_1 = 1,
    NUMBER_2 = 2,
    NUMBER_3
}

Second issue pertains to how DateFormat attributes are being generated. Would prefer them to be of Date type rather than string type.

export interface BillboardBasicInformationDto { 
    city?: string | null;
    ...
    mapUrl?: string | null;
}
public class BillboardBasicInformationDto
{
    public string? City { get; set; }
    ...
    public DateTime BillboardStatusDateFrom { get; set; }
    public DateTime? BillboardStatusDateTo { get; set; }
    ...
}

Contents of config.nswag:

{
  ...
}

And the AddOpenApiDocument configuration:

services.AddOpenApiDocument((configure, sp) =>
{
    ...
});

Appreciate any guidance and apologies for any oversights.

Various attempts have been made to achieve the desired enum format without success.

Answer №1

To address the enum problem you're facing, I have created a custom XEnumNameSchemaFilter based on the resources from this repository. You have the option to utilize the entire package or simply extract the necessary code for your purposes.

Regarding the issue with dates while using aspNetCoreToOpenApi, I currently do not have a solution. In my own experience with a .NET + Angular application, I rely on openApiToTypeScriptClient where a .js file is generated from my swagger.json API definition, featuring a helpful dateTimeType attribute to address Date type problems in TypeScript. It's possible that a similar approach could be applicable in your scenario. I will continue investigating for a solution to address the date issue. If anyone has insights to share, kindly leave a comment so I can incorporate your solution into this response.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Identifying input value changes without needing to manually enter key values

As an example: <input class="table-input" type="number" name="qty" [(ngModel)]="cpy.qty" matInput min="1" max="{{cpy.qty}}" where cpy represents an object that is constantly changing. Currently, I need to execute a certain operati ...

Using Msgpack between a C# application and a Node.js program: a beginner's guide

I was able to transfer data between a C# and C++ program using the same class through ZMQ. In this case, the C++ class served as the data definition and the compiler conveniently handled the byte-array to class conversion. But now I'm wondering how I ...

The installed local Angular version is outdated compared to the current project version

I've been having trouble customizing my Angular CLI because a package I need only works with an older version of Angular. Currently, my global Angular version is 15.2.9. However, when I create a new Angular project using ng new, the package.json shows ...

Running Jenkins in a Docker container to initiate the process of building an Angular application within a

Recently, I began my journey of learning Jenkins and successfully launched it on Docker. Now, I have a project built in Angular along with a Dockerfile created to produce a Docker image. However, when attempting to start the process from Jenkins, an erro ...

A versatile function capable of invoking two APIs simultaneously, with one of them being designed to return an array

Here is the code snippet that I am working with: getElements(apiUrl: string): Observable<Element[]> { return this.httpClient.get<any>(apiUrl + 'test/elements').pipe( catchError(error => { if(error.status === ...

Unable to instantiate FormData with the constructor

Within my Angular application, I have a basic form setup like this: <form [formGroup]="loginForm" (submit)="login()"> <div id="container-credentials"> <input type="text" name="username" formControlName="username"> <input typ ...

Error: Undefined object trying to access 'vibrate' property

Good day, I apologize for my poor English. I am encountering an issue with Ionic Capacitor while attempting to utilize the Vibration plugin. The documentation lacks detailed information, and when checking the Android Studio terminal, I found the following ...

Encountered a bug in the findUnique function within the services of a Nest JS and Prisma project

I have a question about using Prisma with Nest. I keep encountering this error: src/modules/auth/auth.service.ts:28:63 - error TS2322: Type 'UserWhereUniqueInput' is not assignable to type 'string'. 28 const user = await this.prisma ...

How to incorporate a popup modal in your project and where should you place the DialogService constructor

Currently, I am in the process of developing a CRUD ASP.NET Core application using Angular 2 and Typescript. Prior to incorporating a popup feature, this was my output: https://i.stack.imgur.com/vHvCC.png My current task involves placing the "Insert or e ...

"Upon invoking the services provider in Ionic 2, an unexpected undefined value was

I encountered an issue while setting a value in the constructor of my page's constructor class. I made a call to the provider to fetch data. Within the service call, I was able to retrieve the data successfully. However, when I tried to access my vari ...

Choosing From Optional Symbols

Is it feasible to create a custom utility type in TypeScript that resembles the Pick-style, allowing for specified keys that may or may not exist on the selected object type? For example: interface Alpha { a: boolean; b: boolean; } type Selecte ...

typescript decorator implemented on a class that is nested within another class

Is it possible to decorate a nested property within a class? Let's explore with an example: function log(name: string = 'DecoratedProp') { return function logHandler(target: any, field: any) { // get the key ...

Using ngModel to retrieve and display only the month, year, and date

Currently, I am working with an interface named Person which includes fields such as name, last name, birthday, and others. However, I am facing a confusion when it comes to the person's birthday format, as it contains some additional letters at the e ...

Having trouble resolving the npm ERR with @angular-devkit/[email protected]? Found the solution to fixing it by checking out @angular/[email protected] instead

When I try to update the local Angular CLI version, I keep encountering an error with this command: npm uninstall --save-dev angular-cli. (following instructions from this source) npm ERR! code ERESOLVE npm ERR! ERESOLVE could not resolve npm ERR! npm ER ...

Adjust the design of your Angular 2/5 app based on configuration file dynamically

I'm currently exploring the concept of a flexible layout that can be customized by users. Here's how it works: By default, there is a set layout of elements on the page (such as inputs, tables, etc). The user has the ability to rearrange where ...

Error message from Angular development server: Channel is reporting an error in handling the response. The UNK/SW_UNREACHABLE options

After recently installing a new Angular app, I encountered an issue while running 'ng serve'. The application initially loads without any problems, but after a few seconds, I started seeing a strange error in the console. Channel: Error in handle ...

How can Angular CLI add extra static resources while live reloading?

Currently, I am utilizing the most recent version of the Angular CLI. The issue I'm facing involves mock http calls that reference local JSON files such as '../app/myfile.json'. When I reload the application, I consistently encounter 404 err ...

Tips for modifying a resource assembly within a C# .net program

Currently, I am working on modifying an existing string/icon resource assembly coded in C# in Visual Studio. I have researched various methods to edit the binary file directly, with the main tool being mono.cecil (http://www.mono-project.com/docs/tools+lib ...

Is it possible to import a class from a different project or module in TypeScript?

I am attempting to modify the build task in Typescript within this specific project: https://github.com/Microsoft/app-store-vsts-extension/blob/master/Tasks/app-store-promote/app-store-promote.ts I am looking to incorporate an import similar to the one be ...

Avoid using `@typescript-eslint/no-floating-promises` when using a `const` function

Can anyone help me understand why the @typescript-eslint/no-floating-promises rule works with some async functions but not all? To my understanding, these two functions should be equivalent: const getUser = async (userId: string): Promise<User> => ...