swagger-api / swagger-api/swagger-codegen
[Maven /Java / Resttemplate]How set authentication independently of swagger file
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
It seems to be not possible to change authetication for Code generated for Java with Resttemplate:
protected void init() {
// Use RFC3339 format for date and datetime.
// See http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14
this.dateFormat = new RFC3339DateFormat();
// Use UTC as the default time zone.
this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
// Set default User-Agent.
setUserAgent("Java-SDK");
// Setup authentications (key: authentication name, value: authentication).
authentications = new HashMap<String, Authentication>();
// Prevent the authentications from being modified.
authentications = Collections.unmodifiableMap(authentications); }
In my case the basic auth layer is put on top separately. The only way i found is manually add the basic auth into swagger file what does not fit into our build process.
Is there any way to configure the security independently of api spec?
Swagger-codegen version
Maven plugin 2.3.1
Swagger declaration file content or url
Command line used for generation
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<generateApiTests>false</generateApiTests>
<generateModelTests>false</generateModelTests>
<generateSupportingFiles>false</generateSupportingFiles>
<environmentVariables>
<supportingFiles>ApiClient.java,Authentication.java,OAuth.java,ApiKeyAuth.java,HttpBasicAuth.java,RFC3339DateFormat.java</supportingFiles>
</environmentVariables>
<inputSpec>${project.basedir}/src/main/resources/api-tpz.json</inputSpec>
<language>java</language>
<configOptions>
<library>resttemplate</library>
<dateLibrary>java8</dateLibrary>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
mvn compile
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the generated Java RestTemplate client, especially ApiClient.java and the authentication support files listed in the Maven configuration: Authentication.java, OAuth.java, ApiKeyAuth.java, and HttpBasicAuth.java. Trace how init() creates and exposes authentication settings, then determine what configuration boundary would allow authentication to be supplied independently of the Swagger specification. Done means the Maven-generated client can receive that configuration without editing the API definition.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, authentication
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100