Troubles with creating a schema for legacy json response porting to phoenix and phoenix_swagger

I’m porting some legacy routes into a phoenix api that I’m documenting using phoenix_swagger. It has been fine so far but started running into so old json responses that are causing me issues.

The json object returned resembles starts like so

{
  "_embedded": {
    "rel:some_field": [
      {

so obviously something like rel:some_field Schema.ref(:RelatedObject) isn’t going to work with the dsl and I’ve tried several combinations looking through the docs but no success so far. Thought I would try the phone a friend option. Any help would be greatly appreciated.

Can you show what error are you getting?

2 Likes

Sorry for the delayed response. I was originally trying to make all changes transparent to any clients but did end up making some slight changes to them to make it work but figuring out a way to do this will probably be helpful as I try to move more legacy systems into phoenix without breaking existing clients. I’ve been using the phoenix swagger dsl to define all schema and resources so far so was trying to use that here but it obviously posing some issues when special characters are involved. I will probably have to look into the code for the project to get a better idea what is doing behind the scenes. Without posting everything, I can say something like this works:

      IndustryTrends: swagger_schema do
        properties do
          toe_id :string
          industry_trends (Schema.new do
            all_of [
              Schema.new do
                properties do
                  analysis_id :string
                  date :string
                  industry :string
                  toe_id :string
                end
              end
            ]
          end)
        end
      end

but this doesn’t

                properties do
                  analysis:id :string
                  date :string
                  industry :string
                  toe_id :string
                end

This wasn’t the original field I was trying to do but just running this as an example of the code and the exception

== Compilation error in file lib/project_name/v0/controllers/industry_trends_controller.ex ==
** (SyntaxError) lib/project_name/v0/controllers/industry_trends_controller.ex:151: keyword argument must be followed by space after: analysis:
    (elixir) lib/kernel/parallel_compiler.ex:208: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/6

I tried changing a few things like quotes or creating the schema without the dsl but didn’t have anything working and decided to just make some small changes in the client but having a workaround will probably be very useful in the future as I plan to move more stuff off of our old stack since I can’t just kill it for the foreseeable future.

Sorry again for the super late reply.