[SOLVED] API client generated from OpenAPI spec is unable to parse response

I’m submitting a…

  • [ ] Regression (a behavior that stopped working in a new release)
  • [X] Bug report
  • [ ] Performance issue
  • [ ] Documentation issue or request

Current behavior

I use the standard OpenApiReference item in a csproj to automatically generate an API client from an openapi file I downloaded from squidex (by navigating to app -> API -> Content API). When I use this client to request a content item, I receive the following error:

MyNamespace.Content.ApiException: Could not deserialize the response body stream as MyNameSpace.Content.MyContentDto.

Status: 200
Response:

   ---> Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: {. Path 'data.SomeProperty', line 1, position 148.
     at Newtonsoft.Json.JsonTextReader.ReadStringValue(ReadType readType)
     at Newtonsoft.Json.JsonTextReader.ReadAsString()
     at Newtonsoft.Json.JsonReader.ReadForType(JsonContract contract, Boolean hasConverter)

Expected behavior

This should work out of the box, and I suspect the content API does not conform to the OpenAPI generated by Squidex.

Minimal reproduction of the problem

Sorry, I am not at libery to share the code. But this should be trivial to reproduce.

Environment

  • [X] Self hosted with docker
  • [ ] Self hosted with IIS
  • [ ] Self hosted with other version
  • [ ] Cloud version

Version: {“version”:“6.5.0.0”}

Browser:

  • [X] Chrome (desktop)
  • [X] Chrome (Android)
  • [X] Chrome (iOS)
  • [X] Firefox
  • [X] Safari (desktop)
  • [X] Safari (iOS)
  • [X] IE
  • [X] Edge

Others:

What do you mean with “Latest”? Master or a release?

The version number is apparently 6.5.0.0 according to /api/info. The install was done using this guide https://docs.squidex.io/01-getting-started/installation/platforms/install-on-azure.

I have pushed a potential fix to the master branch.

I found out that I might be using the API wrong, so I tried setting the X-Flatten flag, but I can’t see any difference in the output from the API.

There are two specs: One for flat and one “not-flat”. There was a bug where a boolean was not set properly.

But the generated client you have created should work with X-Flatten header. Try X-Flatten=1

I tried
client.DefaultRequestHeaders.Add("X-Flatten", "true");
and
client.DefaultRequestHeaders.Add("X-Flatten", "1");
but neither seems to make a difference.

How do I update my image with the latest changes from master? Do you automatically push the updates to DockerHub?

Yes, I push the result, but the build failed and I have to rerun it. I will tell you the docker tag, when it is completed.

Great, thank you very much!

I had to add the header like so:

httpClient.DefaultRequestHeaders.TryAddWithoutValidation("X-Flatten", "1");

Also ensure to specify the language if you have localized fields with

httpClient.DefaultRequestHeaders.TryAddWithoutValidation("X-Languages", "e");

https://docs.squidex.io/02-documentation/concepts/localization#x-flatten-header

The docker tag is dev-6655

Hi Sebastian,

I updated the Azure Web App with the following command:

az webapp config container set --docker-custom-image-name "squidex/squidex:dev-6655" --name myAppName --resource-group myRgName

After restarting the web app, I now get the following response from /api/info:

{"version":"5.0.0.0"}

I find this rather odd. Is this expected behaviour? Did I somehow downgrade from 6.5 to 5.0?

There is a default version in the dockerfile which is set to the major version and then overriden for each release: https://github.com/Squidex/squidex/blob/master/Dockerfile#L6

Unfortunately I have not found an easy way to update this automatically with each release, so the dev builds only have the same major version.

I just have forgotten to update it.

You may close this issue, we decided to just get the raw JSON without using OpenAPI and map the content on the frontend.

Have you had other issues with the image?

You can also use the Client Library: https://docs.squidex.io/02-documentation/software-development-kits/.net-standard

The does the client library have a method to get all content for a given app and schema, corresponding to the /api/content/[app]/[schema] endpoint in the API?

The dev-6655 image did not work with our database, it returned a 500 error when I tried to open the contents page. Reverting to the latest image fixed that. I don’t have any logs, sorry.

Yes, but you have to create the models manually.

If you can, you could provide me a backup of your database, I am really worried about this.

This topic was automatically closed after 2 days. New replies are no longer allowed.