Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codegen fails when a servers url contains a variable #1897

Closed
sammy-da opened this issue Dec 17, 2023 · 3 comments · Fixed by #1898
Closed

Codegen fails when a servers url contains a variable #1897

sammy-da opened this issue Dec 17, 2023 · 3 comments · Fixed by #1898

Comments

@sammy-da
Copy link

Codegenration fails for openapi specs that contains a variable in the server url:

   "servers": [
      {
         "url": "https://{subdomain}.foo.bar",
         "variables": {
            "subdomain": {
               "default": "your-app-subdomain",
               "description": "Your application's subdomain"
            }
         }
      }
   ]

The generation fails with:

Error:Error attempting to process /Users/some/path/app-v2-api.json:

java.net.URISyntaxException: Illegal character in authority at index 8: https://{subdomain}.foo.bar
        at dev.guardrail.Common$.$anonfun$prepareDefinitions$5(Common.scala:53)
          ...
        at dev.guardrail.Common$.$anonfun$prepareDefinitions$3(Common.scala:52)
          ...
        at dev.guardrail.core.IndexedDistributive$.cotraverse(IndexedDistributive.scala:18)
        at dev.guardrail.core.IndexedDistributiveImplicits$IndexedDistributiveSyntax.cotraverse(IndexedDistributive.scala:24)
        at dev.guardrail.core.IndexedDistributiveImplicits$IndexedDistributiveSyntax.flatExtract(IndexedDistributive.scala:27)
        at dev.guardrail.Common$.$anonfun$prepareDefinitions$1(Common.scala:48)
        at dev.guardrail.Target$$anon$1.traverse(Target.scala:61)
        at dev.guardrail.Target$$anon$1.traverse(Target.scala:29)
          ...
        at dev.guardrail.Target$$anon$1.map(Target.scala:29)
          ...
        at dev.guardrail.Common$.prepareDefinitions(Common.scala:42)
        at dev.guardrail.core.CoreTermInterp.$anonfun$processArgSet$17(CoreTermInterp.scala:135)
        at dev.guardrail.TargetValue.flatMap(Target.scala:103)
        at dev.guardrail.core.CoreTermInterp.$anonfun$processArgSet$16(CoreTermInterp.scala:133)
        at dev.guardrail.TargetValue.flatMap(Target.scala:103)
        at dev.guardrail.core.CoreTermInterp.$anonfun$processArgSet$15(CoreTermInterp.scala:132)
        at dev.guardrail.TargetValue.flatMap(Target.scala:103)
        at dev.guardrail.core.CoreTermInterp.$anonfun$processArgSet$14(CoreTermInterp.scala:131)
        at dev.guardrail.ReadSwagger$.$anonfun$readSwagger$4(ReadSwagger.scala:25)
        at dev.guardrail.TargetValue.flatMap(Target.scala:103)
        at dev.guardrail.ReadSwagger$.readSwagger(ReadSwagger.scala:25)
        at dev.guardrail.runner.GuardrailRunner.$anonfun$guardrailRunner$3(GuardrailRunner.scala:18)
          ...
        at dev.guardrail.TargetValue.flatMap(Target.scala:103)
        at dev.guardrail.Target$$anon$1.flatMap(Target.scala:38)
        at dev.guardrail.Target$$anon$1.flatMap(Target.scala:29)
          ...
        at dev.guardrail.Target$$anon$1.map2Eval(Target.scala:29)
          ...
        at dev.guardrail.runner.GuardrailRunner.$anonfun$guardrailRunner$2(GuardrailRunner.scala:16)
        at dev.guardrail.TargetValue.flatMap(Target.scala:103)
        at dev.guardrail.runner.GuardrailRunner.$anonfun$guardrailRunner$1(GuardrailRunner.scala:16)
        at dev.guardrail.sbt.Tasks$.guardrailTask(Tasks.scala:37)
        at dev.guardrail.sbt.AbstractGuardrailPlugin.calcResult$1(AbstractCodegenPlugin.scala:198)
        at dev.guardrail.sbt.AbstractGuardrailPlugin.$anonfun$cachedGuardrailTask$3(AbstractCodegenPlugin.scala:205)
        at dev.guardrail.sbt.AbstractGuardrailPlugin.$anonfun$cachedGuardrailTask$3$adapted(AbstractCodegenPlugin.scala:203)
          ...
        at dev.guardrail.sbt.AbstractGuardrailPlugin.$anonfun$cachedGuardrailTask$2(AbstractCodegenPlugin.scala:215)
          ...
        at dev.guardrail.sbt.AbstractGuardrailPlugin.cachedGuardrailTask(AbstractCodegenPlugin.scala:218)
        at dev.guardrail.sbt.AbstractGuardrailPlugin.$anonfun$scopedSettings$5(AbstractCodegenPlugin.scala:228)
          ...

Ideally, guardrail could support server variables, but if not, it should just ignore the {} and proceed rather than fail.

@sammy-da sammy-da changed the title Cannot generate client when a servers url contains a variable Codegen fails when a servers url contains a variable Dec 17, 2023
blast-hardcheese added a commit to blast-hardcheese/guardrail that referenced this issue Dec 17, 2023
blast-hardcheese added a commit to blast-hardcheese/guardrail that referenced this issue Dec 17, 2023
@blast-hardcheese
Copy link
Member

@sammy-da Good find! Multiple server support with variables is something that needs to be addressed properly before 1.0 release. I'll release a bugfix with this shortly.

@blast-hardcheese
Copy link
Member

OK. Please try putting the following in your project/guardrail.sbt:

libraryDependencies += "dev.guardrail" %% "guardrail-core" % "0.75.4"

It may take some time to propagate.

blast-hardcheese added a commit to blast-hardcheese/guardrail that referenced this issue Dec 18, 2023
blast-hardcheese added a commit to blast-hardcheese/guardrail that referenced this issue Dec 18, 2023
@blast-hardcheese
Copy link
Member

Closing this as the workaround has been published, future updates on proper server object handling will be posted in #602

Thanks for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants