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

ConjureDecoder does not throw when array passed as object #155

Open
DHerls opened this issue Feb 6, 2024 · 0 comments
Open

ConjureDecoder does not throw when array passed as object #155

DHerls opened this issue Feb 6, 2024 · 0 comments

Comments

@DHerls
Copy link

DHerls commented Feb 6, 2024

What happened?

For the following conjure spec:

types:
  definitions:
    default-package: com.company.product
    objects:

      Recipe:
        fields:
          name: RecipeName
          steps: StringList

      StringList:
        fields:
          items:
            type: list<string>
            safety: safe

      RecipeName:
        alias: string
        safety: safe

services:
  RecipeBookService:
    name: Recipe Book
    package: com.company.product
    base-path: /recipes
    endpoints:
      createRecipe:
        http: POST /
        args:
          createRecipeRequest:
            param-type: body
            type: Recipe

With the following python code

from conjure_python_client import ConjureDecoder, ConjureEncoder

decoder = ConjureDecoder()
incorrect = decoder.decode({"name": "test", "steps": ["test"]}, Recipe)
print(incorrect)

I get the following output:

Recipe(name='test', steps=StringList(items=[]))

So there was a silent failure that inserted a blank object and a blank array

What did you want to happen?

An error should be thrown, same as if you tried to decode a string type as an int.

I would expect an error to be thrown since this is an incorrect type provided

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

No branches or pull requests

1 participant