You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@atlas.apache.org by "lexaneon@gmail.com" <le...@gmail.com> on 2020/02/11 13:18:14 UTC

issues with swagger.json API

Hello,

I would like to share my experience of using API which is generated against swagger json (http://atlas.apache.org/api/v2/ui/index.html#!/TypesREST/getTypeDefByName <http://atlas.apache.org/api/v2/ui/index.html#!/TypesREST/getTypeDefByName>    json: http://atlas.apache.org/api/v2/ui/swagger.json) and hope that you can get me any suggestions.
in swagger.json <http://atlas.apache.org/api/v2/ui/swagger.json> there is no legs which are responsible for security, that is why when creating instance of ApiClient  and set user name\password there is problem like this <https://github.com/swagger-api/swagger-codegen/issues/1054> - ApiClient.setUsername throw exception "No HTTP basic authentication configured!"

 (swagger is not add auth methods to ApiClient constructor, it looks like:
public ApiClient() {
    httpClient = new OkHttpClient();

    verifyingSsl = true;

    json = new JSON();

    // Set default User-Agent.
    setUserAgent("Swagger-Codegen/1.0.0/java");

    // Setup authentications (key: authentication name, value: authentication).
    authentications = new HashMap<String, Authentication>();
    // Prevent the authentications from being modified.
    authentications = Collections.unmodifiableMap(authentications);
}
I've resolved this issue - just added next fields to swagger.json and regenerate java-class through codegen
"security": {
      "basicAuth": []
  },
  "securityDefinitions": {
    "basicAuth":{
      "type": "basic"
    }
  },

Pls. fix this issue in your swagger.json tamplate or say where I can find correct one.

2. I tried use TypesRestApi.getTypeDefByName(“hive_table”)
but there is one more issue:

Exception in thread "main" java.lang.IllegalArgumentException: missing discriminator field: <>
	at io.swagger.client.JSON.getDiscriminatorValue(JSON.java:423)
	at io.swagger.client.JSON.access$000(JSON.java:43)
	at io.swagger.client.JSON$14.getClassForElement(JSON.java:198)
	at io.gsonfire.gson.TypeSelectorTypeAdapterFactory$TypeSelectorTypeAdapter.read(TypeSelectorTypeAdapterFactory.java:65)
	at io.gsonfire.gson.NullableTypeAdapter.read(NullableTypeAdapter.java:36)
	at io.gsonfire.gson.HooksTypeAdapter.deserialize(HooksTypeAdapter.java:86)
	at io.gsonfire.gson.HooksTypeAdapter.read(HooksTypeAdapter.java:54)
	at com.google.gson.Gson.fromJson(Gson.java:887)
	at com.google.gson.Gson.fromJson(Gson.java:852)
	at com.google.gson.Gson.fromJson(Gson.java:801)
	at io.swagger.client.JSON.deserialize(JSON.java:497)
	at io.swagger.client.ApiClient.deserialize(ApiClient.java:710)
	at io.swagger.client.ApiClient.handleResponse(ApiClient.java:913)
	at io.swagger.client.ApiClient.execute(ApiClient.java:840)
	at io.swagger.client.api.TypesRestApi.getTypeDefByNameWithHttpInfo(TypesRestApi.java:1999)
	at io.swagger.client.api.TypesRestApi.getTypeDefByName(TypesRestApi.java:1985)
	at SwaggerApiTest$.getTypeDefByName(SwaggerApiTest.scala:34)
	at SwaggerApiTest$.delayedEndpoint$SwaggerApiTest$1(SwaggerApiTest.scala:17)
	at SwaggerApiTest$delayedInit$body.apply(SwaggerApiTest.scala:7)
	at scala.Function0.apply$mcV$sp(Function0.scala:39)
	at scala.Function0.apply$mcV$sp$(Function0.scala:39)
	at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:17)
	at scala.App.$anonfun$main$1(App.scala:73)
	at scala.App.$anonfun$main$1$adapted(App.scala:73)
	at scala.App$$Lambda$1/1196765369.apply(Unknown Source)
	at scala.collection.IterableOnceOps.foreach(IterableOnce.scala:553)
	at scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:551)
	at scala.collection.AbstractIterable.foreach(Iterable.scala:921)
	at scala.App.main(App.scala:73)
	at scala.App.main$(App.scala:71)
	at SwaggerApiTest$.main(SwaggerApiTest.scala:7)
	at SwaggerApiTest.main(SwaggerApiTest.scala)

and at this step I don’t know how I can fix this.
I would grateful if you send me example how I should use it or just point on me mistakes.

here is my code for #2
import java.util.Base64

import io.swagger.client.{ApiClient}
import io.swagger.client.api.TypesRestApi
import org.apache.http._

object SwaggerApiTest extends App{

  val apiClient = new ApiClient()
  val (atlasUsename, atalsPassword) = ("admin", "admin")
  val connectStr = "Basic " + new String(Base64.getEncoder.encode((atlasUsename + ":" + atalsPassword).getBytes))
  apiClient.setBasePath("http://localhost:21000/api/atlas")
  apiClient.addDefaultHeader(HttpHeaders.AUTHORIZATION, connectStr)
  val typesRestApi = new TypesRestApi(apiClient)
  apiClient.setDebugging(true)
//  testGetTypesDef()
  getTypeDefByName("hive_table")

  def testGetTypesDef() ={
    val listTypeDefDeaders = typesRestApi.getTypeDefHeaders

    listTypeDefDeaders.forEach(x => println(x.getName()))
  }
  def getTypeDefByName(typeDefName: String)={

    val typeDef = typesRestApi.getTypeDefByName(typeDefName)
    typeDef

  }

}
I look forward to hearing from you in the nearest future.

Kind regards,
Aleksey.