Git Product home page Git Product logo

Comments (11)

crdoconnor avatar crdoconnor commented on August 10, 2024 5

Dirty load is now available and implemented in version 0.13.0:

http://hitchdev.com/strictyaml/using/alpha/restrictions/loading-dirty-yaml/

from strictyaml.

crdoconnor avatar crdoconnor commented on August 10, 2024 2

Yeah, I'm coming around to this idea. Except for the duplicate keys thing (I don't think anybody would actually want that), I might create a special method for parsing disallowed YAML.

I think I'll probably have to turn off roundtripping too, since parsing this stuff opens up a can of worms that I don't really want to get in to.

from strictyaml.

hax avatar hax commented on August 10, 2024 2

"dirty load" seems really dirty :)

  1. adding this as some sort of special case where flow style is allowed, but only for empty lists and mappings (which makes me a bit uncomfortable).

Theoretically only empty lists/mappings is the issue, so adding special case is not bad at all :P


Before I know strictyaml, I actually already write yaml close to strictyaml, I avoid flow style in most cases, the only case I want to use flow style is when the data is simple enough so it could be wrote in one line.

So I think maybe we could introduce one-line style (only allow non-nested flow style in one line) which make it not very "special" but also useful?

from strictyaml.

crdoconnor avatar crdoconnor commented on August 10, 2024 1

On the other hand I've just noticed woocart@8963a53 by @zupo which suggests that you're not the only one that wants this, so maybe I should rein in my objections to flow style and at least allow it to be turned on via an optional parameter...

from strictyaml.

numberoverzero avatar numberoverzero commented on August 10, 2024 1

Would you consider a set of flags that has a discouraging name so most people don't enable them?

class PoorForm:
    FLOW_MAPPING = 1
    DUPLICATE_KEYS = 2
    ANCHOR_TOKENS = 4

and usage:

from strictyaml import load, PoorForm


bad_swagger_decisions = PoorForm.FLOW_MAPPING | PoorForm.ANCHOR_TOKENS
with open("v1.yaml", "r") as f:
    spec = load(f.read(), allow=bad_swagger_decisions)

from strictyaml.

gunpinyo avatar gunpinyo commented on August 10, 2024 1

I just come across StrictYAML and really like the idea, but the restriction of flow mapping was about to be my deal-breaker: I was wonder why this is a bad thing? It is indeed a good way to write a short list/dict in a single line: allowing us to write more compact YAML files, which is more human-readable.

Then, I realise the motivation of this restriction is; in fact, the multiline flow mapping, which I completely agree that it should be forbidden. However, I agree with @hax that a single line flow mapping should be allowed with the reason of my paragraph above.

from strictyaml.

crdoconnor avatar crdoconnor commented on August 10, 2024

Hi @numberoverzero thanks for your issue. I'm really sorry I haven't gotten back to you sooner. I was on holiday for the last couple of weeks (and with only intermittent internet access). I won't be so unresponsive from now on.

As to your question, I see two ways of dealing with it. Either make your YAML like this (e.g. by running it through ruamel.yaml first and then changing just those things):

paths:
  /users/{userId}/widgets/{widgetId}/revisions:
    post:
      operationId: createWidgetRevision
      security:
        - apiToken: 

You can then use the EmptyList validator you could interpret the blank value as an empty list.

Or changing the document to be like this:

paths:
  /users/{userId}/widgets/{widgetId}/revisions:
    post:
      operationId: createWidgetRevision
      security:
        - apiToken: '[]'

Using Enum("[]") you could ensure that it is only possible to parse a string of '[]'. This is possibly less ideal since you don't really want to get back "[]" as a string.

Unfortunately I don't see another happy way of dealing with this problem without 1) enabling flow style completely or 2) adding this as some sort of special case where flow style is allowed, but only for empty lists and mappings (which makes me a bit uncomfortable).

from strictyaml.

zupo avatar zupo commented on August 10, 2024

Yep, my use case is restricted to how PHP works (i.e. how PHP is broken) so I couldn't fix the source YAML but had to do a workaround in a fork.

from strictyaml.

numberoverzero avatar numberoverzero commented on August 10, 2024

Thanks for adding this! Docs look great too.

from strictyaml.

crdoconnor avatar crdoconnor commented on August 10, 2024

from strictyaml.

crdoconnor avatar crdoconnor commented on August 10, 2024

Also note that comma separated lists on a single line can be parsed with https://hitchdev.com/strictyaml/using/alpha/scalar/comma-separated/

This is shorter (no opening [ and closing ] required), explicitly type-safe and, IMO, a little more non-programmer friendly than flow-style lists.

from strictyaml.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.