oatpp / oatpp-swagger

OpenApi 3.0.0 docs + Swagger UI for oatpp services
https://oatpp.io/
Apache License 2.0
94 stars 53 forks source link

Dynamic hostname #57

Closed MattC11 closed 2 years ago

MattC11 commented 2 years ago

Is there a way to support a dynamic hostname? I want the browser to figure out the hostname and substitute it that for that.

Right now I don't know the address that the swagger-ui will be hosted on, so have to listed all the interfaces and users have to choose from those which isn't great.

idoop commented 2 years ago

Actually, this should not be specifying the entry point Inlcude IP/Domain and port on the server side. This should automatically populate the request server hostname and port from the browser JavaScript script that loads the Swagger UI page

MattC11 commented 2 years ago

Yes, that's what I want it to do in the javascript using window.hostname, but I don't have a way to generate that through oatpp-swagger.

idoop commented 2 years ago

@MattC11 Just Do Not call function .addServer(arg1,arg2) in oatpp::swagger::DocumentInfo::Builder

  /**
   *  General API docs info
   */
  OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::swagger::DocumentInfo>, swaggerDocumentInfo)([] {

    oatpp::swagger::DocumentInfo::Builder builder;

    builder
    .setTitle("User entity service")
    .setDescription("CRUD API Example project with swagger docs")
    .setVersion("1.0")
    .setContactName("Ivan Ovsyanochka")
    .setContactUrl("https://oatpp.io/")

    .setLicenseName("Apache License, Version 2.0")
    .setLicenseUrl("http://www.apache.org/licenses/LICENSE-2.0");
//    .addServer("http://localhost:8000", "server on localhost");

    return builder.build();

  }());
MattC11 commented 2 years ago

Thanks @idoop , that does exactly what I want.