Comments (11)
Dirty load is now available and implemented in version 0.13.0:
http://hitchdev.com/strictyaml/using/alpha/restrictions/loading-dirty-yaml/
from strictyaml.
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.
"dirty load" seems really dirty :)
- 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.
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.
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.
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.
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.
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.
Thanks for adding this! Docs look great too.
from strictyaml.
from strictyaml.
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)
- Problem loading document with a single string
- Repeated revalidate() raises Invalid state HOT 2
- Failed revalidation leads to inconsistant state
- Fasjo HOT 3
- Website fails to acknowledge that the Norway problem was fixed in YAML 1.2 HOT 2
- strictyaml does not act as "a near-drop in replacement for pyyaml" HOT 4
- The type order of optional arguments affects the results HOT 2
- Date vs Datetime HOT 2
- Support python2.7.18 HOT 2
- 1.7.0 is broken (cannot import name 'ruamel' from partially initialized module 'strictyaml') HOT 5
- Map containing only Optionals does not validate an empty dict
- as_document and load have dissimilar results for CommaSeparated(Int())
- Doesn't Work At All For Lists / Arrays? HOT 4
- New lines after comment line causes `NotImplementedError`
- Feature request/Question: "Optionalize" maps HOT 1
- Thoughts regarding case-sensitivity of keys HOT 6
- Why not: non-Turing complete configuration languages
- Cannot iterate on emtpy list
- BUG: MapCombined documentation different traceback
- Feature: strictyaml.scalar.Time
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from strictyaml.