Typescript-fetch does not implement in any way the ap+key or Oauth2 security definitions, either globally or indivually applied rules.
2.2.1
`````` yaml
swagger: '2.0'
info:
title: foo
description: bar
version: "1.0.0"
host: localhost:3001
schemes:
basePath: /v1
produces:
``````
java -Dmodels -Dapis -DsupportingFiles=api.ts -jar
swagger-codegen-cli-2.2.1.jar generate -l typescript-fetch
-o ./src/api -i swagger.yaml --additional-properties supportsES6=true
@tht13 may I know if you've cycle to contribute the enhancements?
cc @leonyu, @Vrolijkx
I may be able too, if you could provide an example where this has been implemented.
I also noticed that typescript-fetch doesn't implement any parameters which are set in the header.
I think we can work together on this. I should have a PR to populate the header parameters shortly.
Looking at the typescript-angular2, we need something similar to Configuration: https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/typescript-angular2/configuration.mustache
The implementation of configuration can be found here:
https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/typescript-angular2/api.mustache
Yes, I'm copying the code over :)
Btw, I saw the handling of header parameters here in TS Fetch API template: https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/TypeScript-Fetch/api.mustache#L105-L114
Did you see similar code generated for your case?
@tht13 first attempt: https://github.com/swagger-api/swagger-codegen/pull/3983
please review :)
Disclaimer: no expert in Typescript
CI reported the following issues:
api.ts(31,31): error TS2307: Cannot find module 'configuration'.
api.ts(48,5): error TS2392: Multiple constructor implementations are not allowed.
api.ts(53,5): error TS2392: Multiple constructor implementations are not allowed.
I'm checking further.
I can double check later but I don't believe the haHeaderParam section generated, only the ^hasHeaderParam section. However the parameters were added to the method arguments and in the requirement checking section.
I will check your code in the next few hours, thanks for the help ☺️
I just pushed fixes to address the issues reported by the CI and the header parameter issue (should be hasHeaderParams instead of hasHeaderParam).
Please pull my branch to give it a try later.
Latest issues reported by the CI (partial result below):
0 passing (25ms)
12 failing
1) PetApi should add and delete Pet:
TypeError: Cannot read property 'accessToken' of undefined
at Object.exports.PetApiFetchParamCreactor.addPet (node_modules/typescript-fetch-api/dist/api.js:71:31)
at Object.exports.PetApiFp.addPet (node_modules/typescript-fetch-api/dist/api.js:318:58)
at PetApi.addPet (node_modules/typescript-fetch-api/dist/api.js:492:33)
at Context.<anonymous> (dist/test/PetApi.js:11:20)
2) PetApi should get Pet by ID:
TypeError: Cannot read property 'apiKey' of undefined
at Object.exports.PetApiFetchParamCreactor.getPetById (node_modules/typescript-fetch-api/dist/api.js:187:31)
at Object.exports.PetApiFp.getPetById (node_modules/typescript-fetch-api/dist/api.js:399:58)
at PetApi.getPetById (node_modules/typescript-fetch-api/dist/api.js:525:33)
at Context.<anonymous> (dist/test/PetApi.js:15:20)
ref: https://s3.amazonaws.com/archive.travis-ci.org/jobs/167303456/log.txt
Fixed in #4008 and #4005, Header params resoved in v2.2.2 and Security in v2.3.0
@tht13 thanks for your help in fixing this.
May I know if you've time to fix the same for typescript-angular, typescript-angular2 and typescript-node?
I'll put together a PR 👌(or 3)
On Thu, 20 Oct 2016, 15:01 wing328, [email protected] wrote:
@tht13 https://github.com/tht13 thanks for your help in fixing this.
May I know if you've time to fix the same for typescript-angular,
typescript-angular2 and typescript-node?—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/swagger-api/swagger-codegen/issues/3970#issuecomment-255114277,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAx4cCxJnfo7JSs6_O-56i-suhuJaPLyks5q13QvgaJpZM4KU18Q
.
Regards,
Thomas Townsend
+47448960
Hi,
I thought this was still the case, but after deep diving into the mustache code it seems you guys took care of it. Great job!
BUT, I still don't seem to auth added to the output. My guess is that either {{authMethods}} or {{isApiKey}} evaluates to false.
do I need to configure something else other than adding something like the code below to the swagger.json? (I added both oauth and apiKey to test whether I was doing either wrong)
"securityDefinitions": {
"Bearer": {
"type": "apiKey",
"name": "Authorization",
"in": "header"
},
"Token": {
"type": "oauth2",
"flow": "accessCode"
}
},
"security": {
"Token": []
}
Is it legitimate for the field name to be a string that is not a valid identifier in Typescript/Javascript?
I have a Swagger spec in which the name is "x-api-key" and the code that is currently generated by the template breaks because it tries to access it as configuration.apiKey.x-api-key.
Is the spec non-conforming? Or should these keys be handled in a more robust way?
@Aleksion in the endpoint, did you specify which security definition(s) to apply? e.g. https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/test/resources/2_0/petstore.yaml#L183
@ranma42 please open a new issue for tracking.
Btw, please also try the latest master and 2.3.0 to confirm whether the issue still occurs.
@wing238, i did yes. But when we changed to 2.3.0 it worked as it should.
Never got around to update it in this issue though. Sorry about that!
@Aleksion that's ok. Glad to hear that the issue is resolved.
Is there a reason this fix hasn't been merged to master?
Here is the code from 2.3.0 release: https://github.com/swagger-api/swagger-codegen/blob/2.3.0/modules/swagger-codegen/src/main/resources/TypeScript-Fetch/api.mustache#L130
And here is what we have in master: https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/TypeScript-Fetch/api.mustache#L125
Thank you in advance.