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

Issue getting inference working #26

Open
tekanic opened this issue Feb 5, 2022 · 3 comments
Open

Issue getting inference working #26

tekanic opened this issue Feb 5, 2022 · 3 comments
Labels
question Further information is requested

Comments

@tekanic
Copy link

tekanic commented Feb 5, 2022

I setup my amber project with openapi-generator but when I try to get inference working I'm getting a build error that has something to do with the helpers...

There was a problem expanding macro 'macro_4654287824'

Code in lib/openapi-generator/src/openapi-generator/helpers/amber.cr:336:5

336 | {% for method_name, content_type in TYPE %}
^
Called macro defined in lib/openapi-generator/src/openapi-generator/helpers/amber.cr:336:5

336 | {% for method_name, content_type in TYPE %}

Which expanded to:

34 | macro json(schema, content_type)
35 | {% hash_ref = ::OpenAPI::Generator::Helpers::Amber::HASH_ITEM_REF[0] %}
36 | {% code = hash_ref[0] %}
^
Error: undefined macro method 'NilLiteral#[]'

@elbywan elbywan added the question Further information is requested label Feb 6, 2022
@elbywan
Copy link
Owner

elbywan commented Feb 6, 2022

Hi @tekanic,

I setup my amber project with openapi-generator but when I try to get inference working I'm getting a build error that has something to do with the helpers...

I'm sorry but I cannot tell you exactly what is wrong with the information you provided.

Could you describe a bit more how you have setup the library? And in which context you are calling json?

@tekanic
Copy link
Author

tekanic commented Feb 6, 2022

In my application.cr file I have the following setup:

require "openapi-generator"
require "amber"
require "openapi-generator/providers/amber"

require "./settings"
require "./logger"
require "./i18n"
require "./database"
require "./initializers/**"

# Start Generator Dependencies: Don't modify.
require "../src/models/**"
# End Generator Dependencies

require "../src/controllers/application_controller"
require "../src/controllers/**"
require "./routes"

In my routes.cr file I have the following after the Amber::Server.configure block:

OpenAPI::Generator::Helpers::Amber.bootstrap
OpenAPI::Generator.generate(
  provider: OpenAPI::Generator::RoutesProvider::Amber.new,
  options: {
      output: Path[Dir.current] / "public" / "opeanapi.yml"
    },
      base_document: {
      info: {
      title: "TEST",
      version: "v0.1"
  }
  }
)

In my controllers I require openapi-generator/helpers/amber like so:

require "json"
require "openapi-generator/helpers/amber"

class SurveyController < ApplicationController

  include ::OpenAPI::Generator::Controller
  include ::OpenAPI::Generator::Helpers::Amber

[clipped for brevity] 

Is there something I'm doing incorrectly? Perhaps, I did not understand the documenation.

I am using the latest version of crystal and amber. Thanks for the help!

@tekanic
Copy link
Author

tekanic commented Feb 6, 2022

In my controllers (index method), I typically build a json response that looks like this...

{
  "widgets":[widget records [50]...],
  "total_records": 1000,
  "offset": 0,
  "limit": 50
}

How would I programmatically create a schema for this type of response?

Is this enough information or is there something specific that I'm missing? Thanks!

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

No branches or pull requests

2 participants