Issue getting inference working
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#[]'
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?
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!
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!