Should not need to be generated JSON.parse or using it incorrectly?
See original GitHub issue
Code.
public async Task<string> TypeScript()
{
string baseUrl = $"{this.Request.Scheme}://{this.Request.Host.Value.ToString()}{this.Request.PathBase.Value.ToString()}";
OpenApiDocument document = await OpenApiDocument.FromUrlAsync($"{baseUrl}/swagger/v1/swagger.json");
var settings = new TypeScriptClientGeneratorSettings
{
TypeScriptGeneratorSettings = {
TypeScriptVersion = 3.9M,
TypeStyle = TypeScriptTypeStyle.Interface,// Interface,Class or KoObservableClass
DateTimeType = TypeScriptDateTimeType.String,//Date, MomentJS or String
},
Template = TypeScriptTemplate.Axios,
PromiseType = PromiseType.Promise,
HttpClass = HttpClass.HttpClient,
ClassName = "{controller}Client",
};
var generator = new TypeScriptClientGenerator(document, settings);
var code = generator.GenerateFile();
return code;
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:9 (2 by maintainers)
Top Results From Across the Web
Handling bad JSON.parse() in node safely
The best way to catch invalid JSON parsing errors is to put the calls to JSON.parse() to a try/catch block. You really do...
Read more >Anything wrong with direct evaluation of JSON if your own ...
Suppose I have a server-side variable containing JSON, called strJSON that my own code created. Was it created entirely by your code?
Read more >How to Parse Improperly Formatted JSON Objects in ...
Therefore, the problem to solve is to take an invalid text file with valid JSON objects and properly format it for parsing. Instead...
Read more >Error while parsing JSON Response in REST API Post call
I am using Outsystems 10 and trying to consume a REST API (single method). I have copied and pasted the REST Request and...
Read more >SyntaxError: JSON.parse: bad parsing - JavaScript | MDN
JSON.parse() parses a string as JSON. This string has to be valid JSON and will throw this error if incorrect syntax was encountered....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It is true that current version of Axios is using
JSON.parse
by default thanks to it’s default transformResponse but is is also true the implementation is flawed big way as it swallows any error from parsing. Check this 6 years old! issueSo it is a good idea to disable it anyway. Just pass
transformResponse: []
intoaxios.create
I do not use Axios in any projects so I do not what to do here… Can someone create a PR with a fix for this?