mulesoft-labs / raml-java-client-generator

Raml Java Client Generator
Apache License 2.0
34 stars 34 forks source link

securedBy coming from uses is not generating user/password client #43

Closed ca-stefan-cordes closed 5 years ago

ca-stefan-cordes commented 5 years ago

Describe the bug Having a raml file with

uses: 
  candaCommons: exchange_modules/6b05fd51-2fe5-4078-b1a1-83d16894bf76/canda-commons/1.0.8/canda-commons.raml
securedBy: [candaCommons.basicAuth]

with canda-commons.raml

securitySchemes:
  basicAuth:
    displayName: Basic Authentication
    description: This API supports Basic Authentication. The client has to provide an "Authorization" header with valid credentials.
    type: Basic Authentication
    describedBy:
      headers:
        Authorization:
          description: Used to send valid credentials.
          type: string
      responses:
        401:
          description: Credentials are missing or could not be validated by the server.

creates an Client without authentication while

securitySchemes:
  clientid:
    type: Basic Authentication
securedBy: [clientid]

To Reproduce Steps to reproduce the behavior:

  1. Generate from above raml
  2. See public MuletemplateClient(String baseUrl) { generated.

Expected behavior public MuletemplateClient(java.lang.String baseUrl, java.lang.String username, java.lang.String password) { should be generated.

Screenshots

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context

ca-stefan-cordes commented 5 years ago

Looks like the problem is that generator is looking for securitySchemes only (which are empty on root level in case they come from library):

path "securitySchemes" (id=239)
from org.raml.v2.internal.impl.commons.nodes.RamlDocumentNode (id=262)
but path is uses/*/ Thread [main] (Suspended) org.raml.yagi.framework.util.NodeSelector.selectFrom(java.lang.String, org.raml.yagi.framework.nodes.Node) line: 53 org.raml.yagi.framework.model.ModelProxyBuilder$SimpleProxy.fromNodeKey(java.lang.reflect.Method, java.lang.reflect.Type) line: 88 org.raml.yagi.framework.model.ModelProxyBuilder$SimpleProxy.invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[]) line: 70 com.sun.proxy.$Proxy7.securitySchemes() line: not available org.mule.raml.impl.v10.model.ApiModelImpl.getSecuritySchemes() line: 115

Adding Security Schemes from "getSecuredBy" looks like the solution.

machaval commented 5 years ago

Thanks for the PR, it is ready to be consumed on the 0.11 version